Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------- CUSTOM VARIABLES ------
- modemSide = "top"
- clientIDs = {5, 6, 7}
- entryNames = {"NUCLEAR REACTOR", "LAVA PUMP", "MASSFABRICATOR"}
- --- END OF CUSTOM VARIABLES ---
- ------- FILE HANDLER -------
- function writeFile(filename, table)
- file = fs.open(filename, "w")
- file.write(textutils.serialize(table))
- file.close()
- end
- function doIfFileDoesNotExist()
- print("file does not exist")
- end
- function testIfFileExists(filename)
- file = fs.open(filename,"r")
- if file ~= nil then
- file.close()
- return true
- else
- return false
- end
- end
- function deleteFile(filename)
- fs.delete(filename)
- end
- function readFile(filename)
- file = fs.open(filename, "r")
- if file ~= nil then
- table = textutils.unserialize(file.readAll())
- file.close()
- else
- doIfFileDoesNotExist()
- end
- return table
- end
- -- END OF FILE HANDLER --
- if testIfFileExists("entrysTable") == false then
- tableDefault = {
- [1] = false,
- [2] = true,
- [3] = false,
- }
- writeFile("entrysTable", tableDefault)
- end
- entrys = readFile("entrysTable")
- entry1 = entrys[1]
- entry2 = entrys[2]
- entry3 = entrys[3]
- function saveAllEntrys()
- saveTable = {
- [1] = entry1,
- [2] = entry2,
- [3] = entry3,
- }
- writeFile("entrysTable", saveTable)
- end
- function sendEntry1()
- rednet.send(clientIDs[1], entry1)
- saveAllEntrys()
- end
- function sendEntry2()
- rednet.send(clientIDs[2], entry2)
- saveAllEntrys()
- end
- function sendEntry3()
- rednet.send(clientIDs[3], entry3)
- saveAllEntrys()
- end
- rednet.open(modemSide)
- while true do
- term.setBackgroundColor(colors.black)
- shell.run("clear")
- -- ENTRY 1 --
- term.setBackgroundColor(colors.black)
- term.setCursorPos(2,2)
- print(entryNames[1])
- if entry1 == false then
- term.setBackgroundColor(colors.red)
- term.setCursorPos(2,3)
- print("[ DISABLED ]")
- sendEntry1()
- else
- term.setBackgroundColor(colors.green)
- term.setCursorPos(2,3)
- print("[ ENABLED ]")
- sendEntry1()
- end
- -- ENTRY 2 --
- term.setBackgroundColor(colors.black)
- term.setCursorPos(2,5)
- print(entryNames[2])
- if entry2 == false then
- term.setBackgroundColor(colors.red)
- term.setCursorPos(2,6)
- print("[ DISABLED ]")
- sendEntry2()
- else
- term.setBackgroundColor(colors.green)
- term.setCursorPos(2,6)
- print("[ ENABLED ]")
- sendEntry2()
- end
- -- ENTRY 3 --
- term.setBackgroundColor(colors.black)
- term.setCursorPos(2,8)
- print(entryNames[3])
- if entry3 == false then
- term.setBackgroundColor(colors.red)
- term.setCursorPos(2,9)
- print("[ DISABLED ]")
- sendEntry3()
- else
- term.setBackgroundColor(colors.green)
- term.setCursorPos(2,9)
- print("[ ENABLED ]")
- sendEntry3()
- end
- event,side,x,y = os.pullEvent()
- if event == "monitor_touch" then
- -- TOUCH RESPONSE ENTRY 1
- if y == 3 and x >= 2 and x <= 13 then
- if entry1 == false then
- entry1 = true
- else
- entry1 = false
- end
- end
- -- TOUCH RESPONSE ENTRY 2
- if y == 6 and x >= 2 and x <= 13 then
- if entry2 == false then
- entry2 = true
- else
- entry2 = false
- end
- end
- -- TOUCH RESPONSE ENTRY 3
- if y == 9 and x >= 2 and x <= 13 then
- if entry3 == false then
- entry3 = true
- else
- entry3 = false
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement