Advertisement
osmarks

Weather Control System Control System

Jul 29th, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. local obelisk = peripheral.find "weather_obelisk"
  2. local weather_type = settings.get "wcscs.type"
  3. local modem = peripheral.find "modem"
  4. modem.open(666)
  5.  
  6. local weather_modes = {
  7.     sun = 1,
  8.     rain = 2,
  9.     thunder = 3
  10. }
  11.  
  12. local function send(msg)
  13.     modem.transmit(666, 666, msg)
  14. end
  15.  
  16. while true do
  17.     local _, _, _, _, msg = os.pullEvent "modem_message"
  18.     -- protocol: { message type [command/error/result], command, params }
  19.     if type(msg) == "table" and msg[1] == "command" and msg[2] == "set_weather" then
  20.         local set_to = msg[3]
  21.         local mode = weather_modes[set_to]
  22.         if not mode then
  23.             send {"error", msg[2], "invalid weather type " .. tostring(set_to)}
  24.         else
  25.             if weather_type == set_to then
  26.                 print("setting weather to", set_to)
  27.                 local result = obelisk.activate()
  28.                 send { "result", msg[2], result }
  29.             end
  30.         end
  31.     end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement