ksbd

Spawner Test

Jun 9th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. --Constants:
  2.    
  3.     local onMessage = "On"
  4.     local offMessage = "Off"
  5.     local y = 100
  6.     local redNetSide = "top"
  7.     local redSide = "bottom"
  8.     local serverID = 5
  9.  
  10. --Variables:
  11.  
  12.     local x = 1
  13.     local senderId, message, distance
  14.  
  15. --Functions
  16.  
  17. function netClose()
  18.         rednet.close(redNetSide)
  19. end
  20.  
  21. function netOpen()
  22.         netClose()
  23.         rednet.open(redNetSide)
  24. end
  25.  
  26. function countDown()
  27.     if x >= y then
  28.         x = 1
  29.         redReset()
  30.     else
  31.         x=x+1
  32.     end
  33. end
  34.  
  35. function redReset()
  36.     redOff()
  37.     sleep(.5)
  38.     redOn()
  39. end
  40.  
  41. function redOn()
  42.         redstone.setOutput(redSide, true)
  43. end
  44.  
  45. function redOff()
  46.         redstone.setOutput(redSide, false)
  47. end
  48.  
  49. function getData()
  50.         senderId, message, distance = rednet.receive(10)
  51.     print("Waiting for message")
  52. end
  53.  
  54. --Main Program:
  55.  
  56. netOpen()
  57. while true do
  58.     countDown()
  59.     getData()
  60.     print(message)
  61.     if senderId == serverID then
  62.         if message == onMessage then
  63.             print("turning R off, and the spawner on")
  64.             redOff()
  65.         elseif message == offMessage then
  66.             print("turning R on, and the spawner off")
  67.             redOn()
  68.         else
  69.             print("message doesnt apply to me")
  70.         end
  71.     end
  72. end
Advertisement
Add Comment
Please, Sign In to add comment