Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if fs.exists("touchpoint") then
- os.loadAPI("touchpoint")
- else
- shell.run("pastebin", "get", "pFHeia96>", "touchpoint>")
- os.loadAPI("touchpoint")
- end
- if not os.getComputerLabel() then
- write "Set a label for this computer: "
- os.setComputerLabel(read())
- end
- local t = touchpoint.new("left")
- local disabled = false
- local f1, f2, f3, f4 = true, true, true, true
- local level_name = ""
- if fs.exists("buttonSetter") then
- rednet.open("top")
- print("A crash occured")
- print("Reading home position")
- local h = fs.open("buttonSetter", "r")
- f1 = h.readLine() == "true"
- f2 = h.readLine() == "true"
- f3 = h.readLine() == "true"
- f4 = h.readLine() == "true"
- disabled = h.readLine() == "true"
- level_name = tonumber(h.readLine())
- h.close()
- if (disabled == true) then
- t:add("Disabled", nil, 20, 2, 29, 4, colors.lightGray, colors.lightBlue)
- t:add("Farm 1", nil, 1, 2, 8, 4, colors.red, colors.lime)
- t:add("Farm 2", nil, 10, 2, 18, 4, colors.red, colors.lime)
- t:add("Farm 3", nil, 1, 6, 8, 8, colors.red, colors.lime)
- t:add("Farm 4", nil, 10, 6, 18, 8, colors.red, colors.lime)
- rs.setOutput("front", false)
- rs.setOutput("right", false)
- rs.setOutput("back", false)
- rs.setOutput("bottom", false)
- else
- if (f1 == true) then
- t:add("Farm 1", nil, 1, 2, 8, 4, colors.lime, colors.red)
- else
- t:add("Farm 1", nil, 1, 2, 8, 4, colors.red, colors.lime)
- end
- if (f2 == true) then
- t:add("Farm 2", nil, 10, 2, 18, 4, colors.lime, colors.red)
- else
- t:add("Farm 2", nil, 10, 2, 18, 4, colors.red, colors.lime)
- end
- if (f3 == true) then
- t:add("Farm 3", nil, 1, 6, 8, 8, colors.lime, colors.red)
- else
- t:add("Farm 3", nil, 1, 6, 8, 8, colors.red, colors.lime)
- end
- if (f4 == true) then
- t:add("Farm 4", nil, 10, 6, 18, 8, colors.lime, colors.red)
- else
- t:add("Farm 4", nil, 10, 6, 18, 8, colors.red, colors.lime)
- end
- t:add("Enabled", nil, 20, 2, 29, 4, colors.lightGray, colors.lightBlue)
- rs.setOutput("front", f1)
- rs.setOutput("right", f2)
- rs.setOutput("back", f3)
- rs.setOutput("bottom", f4)
- end
- else
- if fs.exists("startup") then
- fs.delete("startup")
- local h = fs.open("startup", "w")
- h.writeLine("sleep(1)")
- h.writeLine("shell.run('" .. shell.getRunningProgram() .. "')")
- h.close()
- else
- local h = fs.open("startup", "w")
- h.writeLine("sleep(1)")
- h.writeLine("shell.run('" .. shell.getRunningProgram() .. "')")
- h.close()
- end
- term.write("Fill nivau of the farm: ")
- level_name = tonumber(read())
- print(" ")
- local h = fs.open("buttonSetter", "w")
- h.writeLine(f1) --front (f1)
- h.writeLine(f2) --right (f2)
- h.writeLine(f3) --back (f3)
- h.writeLine(f4) --bottom (f4)
- h.writeLine(disabled) --disabled
- h.writeLine(level_name)
- h.close()
- rs.setOutput("front", true)
- rs.setOutput("right", true)
- rs.setOutput("back", true)
- rs.setOutput("bottom", true)
- t:add("Farm 1", nil, 1, 2, 8, 4, colors.lime, colors.red)
- t:add("Farm 2", nil, 10, 2, 18, 4, colors.lime, colors.red)
- t:add("Farm 3", nil, 1, 6, 8, 8, colors.lime, colors.red)
- t:add("Farm 4", nil, 10, 6, 18, 8, colors.lime, colors.red)
- t:add("Enabled", nil, 20, 2, 29, 4, colors.lightGray, colors.lightBlue)
- end
- local labelTable = {
- "Level: " .. tostring(level_name),
- label = "level_name"
- }
- t:add(labelTable, nil, 1, 11, 18, 12, colors.lightGray, colors.lightBlue)
- t:draw()
- function saveButtons()
- local h = fs.open("buttonSetter", "w")
- h.writeLine(f1) --bottom (f1)
- h.writeLine(f2) --right (f2)
- h.writeLine(f3) --back (f3)
- h.writeLine(f4) --front (f4)
- h.writeLine(disabled) --disabled
- h.writeLine(level_name)
- h.close()
- end
- while true do
- local event, p1, p2, p3 = t:handleEvents(os.pullEvent())
- if event == "button_click" then
- if (p1 == "Farm 1") and (disabled == false) then
- t:toggleButton(p1)
- rs.setOutput("front", not rs.getOutput("front"))
- f1 = rs.getOutput("front")
- elseif (p1 == "Farm 2") and (disabled == false) then
- t:toggleButton(p1)
- rs.setOutput("right", not rs.getOutput("right"))
- f2 = rs.getOutput("right")
- elseif (p1 == "Farm 3") and (disabled == false) then
- t:toggleButton(p1)
- rs.setOutput("back", not rs.getOutput("back"))
- f3 = rs.getOutput("back")
- elseif (p1 == "Farm 4") and (disabled == false) then
- t:toggleButton(p1)
- rs.setOutput("bottom", not rs.getOutput("bottom"))
- f4 = rs.getOutput("bottom")
- elseif (p1 == "Disabled") then
- t:flash(p1)
- t:rename("Disabled", "Enabled")
- disabled = false
- if (f1 == true) then
- rs.setOutput("front", true)
- t:toggleButton("Farm 1")
- end
- if (f2 == true) then
- rs.setOutput("right", true)
- t:toggleButton("Farm 2")
- end
- if (f3 == true) then
- rs.setOutput("back", true)
- t:toggleButton("Farm 3")
- end
- if (f4 == true) then
- rs.setOutput("bottom", true)
- t:toggleButton("Farm 4")
- end
- elseif (p1 == "Enabled") then
- t:flash(p1)
- t:rename("Enabled", "Disabled")
- disabled = true
- if (f1 == true) then
- t:toggleButton("Farm 1")
- end
- if (f2 == true) then
- t:toggleButton("Farm 2")
- end
- if (f3 == true) then
- t:toggleButton("Farm 3")
- end
- if (f4 == true) then
- t:toggleButton("Farm 4")
- end
- rs.setOutput("front", false)
- rs.setOutput("right", false)
- rs.setOutput("back", false)
- rs.setOutput("bottom", false)
- end
- saveButtons()
- elseif p2 ~= nil then
- if (string.find(p2, level_name) and string.find(p2, "enable") and disabled == true) then
- t:rename("Disabled", "Enabled")
- disabled = false
- rs.setOutput("front", true)
- t:toggleButton("Farm 1")
- rs.setOutput("right", true)
- t:toggleButton("Farm 2")
- rs.setOutput("back", true)
- t:toggleButton("Farm 3")
- rs.setOutput("bottom", true)
- t:toggleButton("Farm 4")
- elseif (string.find(p2, level_name) and string.find(p2, "disable") and disabled == false) then
- t:rename("Enabled", "Disabled")
- disabled = true
- if (f1 == true) then
- t:toggleButton("Farm 1")
- end
- if (f2 == true) then
- t:toggleButton("Farm 2")
- end
- if (f3 == true) then
- t:toggleButton("Farm 3")
- end
- if (f4 == true) then
- t:toggleButton("Farm 4")
- end
- rs.setOutput("front", false)
- rs.setOutput("right", false)
- rs.setOutput("back", false)
- rs.setOutput("bottom", false)
- end
- end
- end
Add Comment
Please, Sign In to add comment