Advertisement
Guest User

main

a guest
Jan 22nd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. --[[
  2.  
  3.         MAINFRAME PROGRAM
  4.  
  5. ]]--
  6.  
  7. local function clear()
  8.     term.clear()
  9.     term.setCursorPos(1,1)
  10. end
  11.  
  12.  
  13.  
  14. --[[
  15.         EVENTS AND THEIR PARAMETERS.
  16.  
  17.         redstone: Returns NO parameters.
  18.         modem_message:
  19.                         * param1: string side
  20.                         * param2: number frequency
  21.                         * param3: number replyFrequency
  22.                         * param4: message
  23.                         * param5: number distance travelled
  24.                         - a good way to detect from where the modem message came from is by checking the replyFrequency.
  25.         rednet_message:
  26.                         * param1: number senderID
  27.                         * param2: message
  28.                         * param3: protocol/message travelled
  29.  
  30.         USEFUL KEYPRESS CHEAT SHEET:
  31.                         * arrow up:    200
  32.                         * arrow down:  208
  33.                         * arrow left:  203
  34.                         * arrow right: 205
  35.                         * E:           18
  36.                         * Enter:       28
  37.                         * Space:       57
  38.        
  39.         ERROR DEBUGGING:
  40.                         * Check if event params are in quotation marks. example: if event == "key" then
  41.  
  42. ]]
  43.  
  44. local remotecomp1name = "computer_2"
  45. local monitor = peripheral.wrap("monitor_1")
  46. local modem = peripheral.wrap("bottom")
  47.  
  48. modem.open(1)
  49.  
  50. clear()
  51. print(" * Mainframe")
  52. print(" [E] to exit.")
  53. print(" Modem opened on frequency 1")
  54. term.setCursorPos(1,6)
  55. print("   [1] Farmhouse sensor update")
  56.  
  57.  
  58. while true do
  59.     local event, param1, param2, param3, param4, param5 = os.pullEvent()
  60.  
  61.     -- exit from the program
  62.     if event == "key" and param1 == 18 then
  63.         clear()
  64.         sleep(0.1)
  65.         break
  66.     elseif event == "key" and param1 == 2 then
  67.         local remotecomp = peripheral.wrap(remotecomp1name)
  68.         remotecomp.turnOn()
  69.     elseif event == "redstone" then
  70.         if redstone.testBundledInput("back",1) == true then
  71.             local remotecomp = peripheral.wrap(remotecomp1name)
  72.             remotecomp.turnOn()
  73.         end
  74.     elseif event == "modem_message" and param3 == 2 then
  75.         local time = os.time()
  76.         local ttime = textutils.formatTime(time,true)
  77.         local rmsg = textutils.unserialize(param4)
  78.         print(rmsg[1])
  79.         print(rmsg[2])
  80.         monitor.clear()
  81.         monitor.setCursorPos(1,1)
  82.         monitor.write("Day: "..os.day().." at "..ttime)
  83.         monitor.setCursorPos(1,3)
  84.         monitor.write(rmsg[1].." ["..rmsg[2].."] is in the farmhouse.")
  85.         monitor.setCursorPos(1,4)
  86.         monitor.write("Press T to activate teslas.")
  87.         redstone.setBundledOutput("back",16)
  88.         sleep(0.1)
  89.         redstone.setBundledOutput("back",0)
  90.     end
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement