Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local sides = require("sides")
- local event = require("event")
- local colors = require("colors")
- local md = component.modem
- local rs = component.redstone
- local char_space = string.byte(" ")
- local running = true
- local carts = 0
- local railport = 1234 -- Change this to whatever port you're broadcasting train status stuff on
- md.open(railport)
- local function rsTest()
- if rs.getBundledInput(sides.north, colors.blue) > 0 then
- return true
- else return false
- end
- end
- local function unknownEvent()
- end
- local myEventHandlers = setmetatable({}, { __index = function() return unknownEvent end})
- function myEventHandlers.key_up(adress, char, code, playerName)
- if (char == char_space) then
- rs.setBundledOutput(sides.north, colors.yellow, 0)
- running = false
- end
- end
- function handleEvent(eventID, ...)
- if (eventID) then
- myEventHandlers[eventID](...)
- end
- end
- while running do
- handleEvent(event.pull())
- if (carts >= 5) then
- rs.setBundledOutput(sides.north, colors.yellow, 250)
- md.broadcast(railport, "Change this to whatever you want your network message to be")
- end
- if (rsTest()) then -- Let's check for the directional detector track to have a signal.
- carts = carts + 1
- print(tostring(carts)) -- Debug Output
- end
- os.sleep(0.25) -- Adding this so you can Ctrl+Alt+C out of your program. There are cleaner ways of doing this,
- -- such as pressing 'space' to exit but you would have to code an event handler, or use
- -- one that Kodos wrote
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement