Advertisement
xeritt

Redstone Event

Aug 25th, 2018
155
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None
  1. local event = require('event')  
  2. local internet = require('internet')
  3. local running = true
  4. local char_stop = string.byte("q")
  5.  
  6. local myEventHandlers = {}  
  7. local arg={...}
  8.  
  9. function myEventHandlers.key_up(address, char, code, playerName)
  10.   if (char == char_stop) then
  11.     running = false
  12.     print('bye ' .. playerName .. '!')
  13.   end
  14. end
  15.  
  16. function myEventHandlers.redstone_changed(_, address, side)
  17.   local brightness = 1;
  18.   local str = "on" 
  19.   if side > 0 then
  20.     brightness = 1
  21.     str = "on" 
  22.   else
  23.     brightness = 0
  24.     str = "off"
  25.   end
  26.   print (brightness)   
  27.   local handle = internet.open(arg[1], tonumber(arg[2]))  
  28.   handle:write(str)  
  29.   handle:close()
  30. end
  31.  
  32. function handleEvent(eventID, ...)
  33.   local event = myEventHandlers[eventID]
  34.   if (event) then
  35.     event(...)
  36.   end
  37. end
  38.  
  39. while running do  
  40.   handleEvent(event.pull())
  41. end
Advertisement
RAW Paste Data Copied
Advertisement