Advertisement
Kodos

Angel's Program (Fixed)

Mar 4th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. local component = require("component")
  2. local sides = require("sides")
  3. local event = require("event")
  4. local colors = require("colors")
  5.  
  6. local md = component.modem
  7. local rs = component.redstone
  8.  
  9. local char_space = string.byte(" ")
  10. local running = true
  11. local carts = 0
  12. local railport = 1234 -- Change this to whatever port you're broadcasting train status stuff on
  13.  
  14. md.open(railport)
  15.  
  16. local function rsTest()
  17.   if rs.getBundledInput(sides.north, colors.blue) > 0 then
  18.     return true
  19.   else return false
  20.   end
  21. end
  22.  
  23. local function unknownEvent()
  24. end
  25.  
  26. local myEventHandlers = setmetatable({}, { __index = function() return unknownEvent end})
  27.  
  28. function myEventHandlers.key_up(adress, char, code, playerName)
  29.   if (char == char_space) then
  30.     rs.setBundledOutput(sides.north, colors.yellow, 0)
  31.     running = false
  32.   end
  33. end
  34.  
  35. function handleEvent(eventID, ...)
  36.   if (eventID) then
  37.     myEventHandlers[eventID](...)
  38.   end
  39. end
  40.  
  41.  
  42. while running do
  43. handleEvent(event.pull())
  44.   if (carts >= 5) then
  45.     rs.setBundledOutput(sides.north, colors.yellow, 250)
  46.     md.broadcast(railport, "Change this to whatever you want your network message to be")
  47.   end
  48.  
  49.   if (rsTest()) then    -- Let's check for the directional detector track to have a signal.
  50.     carts = carts + 1
  51.     print(tostring(carts)) -- Debug Output
  52.   end
  53.  
  54.   os.sleep(0.25) -- Adding this so you can Ctrl+Alt+C out of your program. There are cleaner ways of doing this,
  55.               -- such as pressing 'space' to exit but you would have to code an event handler, or use
  56.               -- one that Kodos wrote
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement