Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Edit
- local rulesFile = "rules"
- local rulesEnabled = false
- local notifyEnabled = true
- local header = "Challenges"
- local completedFile = "completed"
- local challengeFile = "challenges"
- local mon = peripheral.wrap("right")
- local autoSyncChallengeName = "" --Should be the same as your challengeFile
- local autoSyncChallengeCode = "" --Pastebin code, leave blank if not in use
- --Edit
- --This program was setup to use 12 advanced monitors in a 3 x 4 pattern
- --"challengeFile" is a file containing the "challenges/task' for a person to do
- --"completedFile" is a file containing true/false answers to whether or not a "challenge/task" has been completed
- --"mon" is the side the monitor is in comparison to the computer
- --"notify" is a true/false value to enable notifications of when the "Rules" button is disabled
- --"rules" is a true/false value to enable the "Rules" button
- --"rulesFile" is a file containing the "rules" for a person to follow
- --****1-9 = MAX 34 CHARACTERS INCLUDING SPACES****
- --****10-99 = MAX 33 CHARACTERS INCLUDING SPACES****
- --****100-224 = MAX 32 CHARACTERS INCLUDING SPACES****
- --Button API will be downloaded on program run, ignore the line below
- --If you do not already have it, the "Button" API pastebin code is S8x0K3ui -> Command: pastebin get S8x0k3ui button *HTTP API MUST BE ENABLED IN CC CONFIG*
- --THE MAX CHARACTERS ONE "RULES" LINE CAN HAVE IS 34
- --The max number of pages is 16, aka 224 "Challenges"
- --Don't mess with anything below this unless you know what are you are doing
- local pages = 1
- local rules = {}
- local pageNum = 1
- local numRules = 0
- local challenges = {}
- local numChallenges = 0
- local completedChallenges = {}
- local rule = io.open(rulesFile, "r")
- local chal = io.open(challengeFile, "r")
- local comp = io.open(completedFile, "r")
- term.clear()
- term.setCursorPos(1,1)
- mon.clear()
- function APILoader(apiName, apiPastebin)
- os.unloadAPI(apiName)
- if fs.exists(apiName) then
- os.loadAPI(apiName)
- else
- shell.run("pastebin","get",apiPastebin,apiName)
- os.loadAPI(apiName)
- end
- end
- function pastebinDownloader(apiName, apiPastebin)
- if fs.exists(apiName) then
- shell.run("delete", apiname)
- shell.run("pastebin","get",apiPastebin,apiName)
- else
- shell.run("pastebin","get",apiPastebin,apiName)
- end
- end
- function autoSync()
- if autoSyncChallengeCode ~= "" then
- pastebinDownloader(autoSyncChallengeName, autoSyncChallengeCode)
- end
- end
- function checkFilesExist()
- if fs.exists(rulesFile) == false then
- file = fs.open(rulesFile, "w")
- file.close()
- end
- if (fs.exists(completedFile) == false) then
- file = fs.open(completedFile, "w")
- file.close()
- end
- if (fs.exists(challengeFile) == false) then
- file = fs.open(challengeFile, "w")
- file.close()
- end
- end
- function heading()
- button.heading(header..":")
- end
- function setupButtons()
- button.setTable("Prev", prevPage, false, "", 1, 6, 18, 20)
- button.setTable("Next", nextPage, false, "", 33, 39, 18, 20)
- setupRules()
- button.screen()
- end
- function setupPages()
- mon.clear()
- button.clearTable()
- heading()
- for i = 1,numChallenges do
- if 14 * i >= numChallenges then
- pages = i
- break
- end
- end
- if pageNum == 1 then
- button.clearTable()
- for i = 1,14 do
- button.label(2, 2+i, i..") ")
- end
- for j = 1,14 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- if j <= 9 then
- x1 = 5
- x2 = string.len(challenges[j]) + 4
- end
- if j >= 10 then
- x1 = 6
- x2 = string.len(challenges[j]) + 5
- end
- y = 2 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- if pageNum == 2 then
- button.clearTable()
- for i = 15,28 do
- button.label(2, -12+i, i..") ")
- end
- for j = 15,28 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- x1 = 6
- x2 = string.len(challenges[j]) + 5
- y = -12 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- if pageNum == 3 then
- button.clearTable()
- for i = 29,42 do
- button.label(2, -26+i, i..") ")
- end
- for j = 29,42 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- x1 = 6
- x2 = string.len(challenges[j]) + 5
- y = -26 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- if pageNum == 4 then
- button.clearTable()
- for i = 43,56 do
- button.label(2, -40+i, i..") ")
- end
- for j = 43,56 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- x1 = 6
- x2 = string.len(challenges[j]) + 5
- y = -40 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- if pageNum == 5 then
- button.clearTable()
- for i = 57, 70 do
- button.label(2, -54+i, i..") ")
- end
- for j = 57, 70 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- x1 = 6
- x2 = string.len(challenges[j]) + 5
- y = -54 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- if pageNum == 6 then
- button.clearTable()
- for i = 71, 84 do
- button.label(2, -68+i, i..") ")
- end
- for j = 71, 84 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- x1 = 6
- x2 = string.len(challenges[j]) + 5
- y = -68 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- if pageNum == 7 then
- button.clearTable()
- for i = 85, 98 do
- button.label(2, -82+i, i..") ")
- end
- for j = 85, 98 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- x1 = 6
- x2 = string.len(challenges[j]) + 5
- y = -82 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- if pageNum == 8 then
- button.clearTable()
- for i = 99, 112 do
- button.label(2, -96+i, i..") ")
- end
- for j = 99, 112 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- if j <= 99 then
- x1 = 6
- x2 = string.len(challenges[j]) + 5
- end
- if j >= 100 then
- x1 = 7
- x2 = string.len(challenges[j]) + 6
- end
- y = -96 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- if pageNum == 9 then
- button.clearTable()
- for i = 113, 126 do
- button.label(2, -110+i, i..") ")
- end
- for j = 113, 126 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- x1 = 7
- x2 = string.len(challenges[j]) + 6
- y = -110 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- if pageNum == 10 then
- button.clearTable()
- for i = 127, 140 do
- button.label(2, -124+i, i..") ")
- end
- for j = 127, 140 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- x1 = 7
- x2 = string.len(challenges[j]) + 6
- y = -124 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- if pageNum == 11 then
- button.clearTable()
- for i = 141, 154 do
- button.label(2, -138+i, i..") ")
- end
- for j = 141, 154 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- x1 = 7
- x2 = string.len(challenges[j]) + 6
- y = -138 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- if pageNum == 12 then
- button.clearTable()
- for i = 155, 168 do
- button.label(2, -152+i, i..") ")
- end
- for j = 155, 168 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- x1 = 7
- x2 = string.len(challenges[j]) + 6
- y = -152 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- if pageNum == 13 then
- button.clearTable()
- for i = 169, 182 do
- button.label(2, -166+i, i..") ")
- end
- for j = 169, 182 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- x1 = 7
- x2 = string.len(challenges[j]) + 6
- y = -166 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- if pageNum == 14 then
- button.clearTable()
- for i = 183, 196 do
- button.label(2, -180+i, i..") ")
- end
- for j = 183, 196 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- x1 = 7
- x2 = string.len(challenges[j]) + 6
- y = -180 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- if pageNum == 15 then
- button.clearTable()
- for i = 197, 210 do
- button.label(2, -194+i, i..") ")
- end
- for j = 197, 210 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- x1 = 7
- x2 = string.len(challenges[j]) + 6
- y = -194 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- if pageNum == 16 then
- button.clearTable()
- for i = 211, 224 do
- button.label(2, -208+i, i..") ")
- end
- for j = 211, 224 do
- if challenges[j] == nil then
- challenges[j] = ""
- end
- x1 = 7
- x2 = string.len(challenges[j]) + 6
- y = -208 + j
- button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
- end
- end
- button.label(15, 19, "Page "..pageNum.." of "..pages)
- setupButtons()
- end
- function setupRules()
- if rulesEnabled == true then
- button.setTable("Rules", displayRules, false, 32, 39, 1, 1)
- else if notifyEnabled == true then
- print("Rules button not enabled! Enable it within the program")
- end
- end
- for line in rule:lines() do
- numRules = numRules + 1
- rules[numRules] = line
- end
- end
- function displayRules()
- mon.clear()
- button.clearTable()
- button.heading("Rules:")
- button.setTable(header, setupPages, false, "", 39-string.len(header), 39, 1, 1)
- for i = 1,numRules do
- button.label(2, 2+i, i..") ")
- end
- for i = 1,numRules do
- button.label(5, 2+i, rules[i])
- end
- button.screen()
- end
- function checkChallenges()
- for line in chal:lines() do
- numChallenges = numChallenges + 1
- challenges[numChallenges] = line
- end
- file = fs.open(completedFile, "r")
- for i = 1,224 do
- completedChallenges[i] = file.readLine()
- end
- end
- function completeChallenge()
- for i = 1,14 do --page 1
- if i <= 9 then
- if x >= 5 and x <= string.len(challenges[i]) + 4 and y == 2 + i then
- completedChallenges[i] = true
- end
- end
- if i > 9 then
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == 2 + i then
- completedChallenges[i] = true
- end
- end
- end
- for i = 15,28 do --page 2
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -12 + i then
- completedChallenges[i] = true
- end
- end
- for i = 29,42 do --page 3
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -26 + i then
- completedChallenges[i] = true
- end
- end
- for i = 43,56 do --page 4
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -40 + i then
- completedChallenges[i] = true
- end
- end
- for i = 57, 70 do --page 5
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -54 + i then
- completedChallenges[i] = true
- end
- end
- for i = 71, 84 do --page 6
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -68 + i then
- completedChallenges[i] = true
- end
- end
- for i = 85, 98 do --page 7
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -82 + i then
- completedChallenges[i] = true
- end
- end
- for i = 99, 112 do --page 8
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -96 + i then
- completedChallenges[i] = true
- end
- end
- for i = 113, 126 do --page 9
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -110 + i then
- completedChallenges[i] = true
- end
- end
- for i = 127, 140 do --page 10
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -124 + i then
- completedChallenges[i] = true
- end
- end
- for i = 141, 154 do --page 11
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -138 + i then
- completedChallenges[i] = true
- end
- end
- for i = 155, 168 do --page 12
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -152 + i then
- completedChallenges[i] = true
- end
- end
- for i = 169, 182 do --page 13
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -166 + i then
- completedChallenges[i] = true
- end
- end
- for i = 183, 196 do --page 14
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -180 + i then
- completedChallenges[i] = true
- end
- end
- for i = 197, 210 do --page 15
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -194 + i then
- completedChallenges[i] = true
- end
- end
- for i = 211, 224 do --page 16
- if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -208 + i then
- completedChallenges[i] = true
- end
- end
- setupPages()
- file = fs.open(completedFile, "w")
- for name, chal in ipairs(completedChallenges) do
- file.writeLine(tostring(chal))
- end
- file.close()
- end
- function convertCompletedChallenges()
- for i = 1,numChallenges do
- if completedChallenges[i] == "true" then
- completedChallenges[i] = true
- else if completedChallenges[i] == "false" then
- completedChallenges[i] = false
- end
- end
- end
- end
- function nextPage()
- if pageNum + 1 <= pages then
- pageNum = pageNum + 1
- end
- setupPages()
- button.flash("Next")
- end
- function prevPage()
- if pageNum - 1 >= 1 then
- pageNum = pageNum - 1
- end
- setupPages()
- button.flash("Prev")
- end
- function checkpress()
- event, side, x, y = os.pullEventRaw("monitor_touch")
- button.checkxy(x,y)
- end
- APILoader("button","S8x0K3ui")
- checkFilesExist()
- autoSync()
- checkChallenges()
- convertCompletedChallenges()
- heading()
- setupPages()
- while true do
- checkpress()
- end
Advertisement
Add Comment
Please, Sign In to add comment