SHOW:
|
|
- or go back to the newest paste.
| 1 | local modem = peripheral.wrap("back")
| |
| 2 | modem.open(999) | |
| 3 | ||
| 4 | function getID(f) | |
| 5 | local id = "Pending" | |
| 6 | if f == 1 then | |
| 7 | id = "Raw Ore Delivery" | |
| 8 | end | |
| 9 | return id | |
| 10 | end | |
| 11 | ||
| 12 | function messageHandler(message, id) | |
| 13 | if message[5] == "ID Request" then | |
| 14 | print("Received "..message[5])
| |
| 15 | modem.transmit(998,999, id) | |
| 16 | print("Sending refresh command")
| |
| 17 | modem.transmit(997,999, "refresh") | |
| 18 | end | |
| 19 | end | |
| 20 | ||
| 21 | function screenClear(y) | |
| 22 | local mX, mY = term.getSize() | |
| 23 | for i = y,mY do | |
| 24 | term.setCursorPos(1,i) | |
| 25 | term.clearLine() | |
| 26 | end | |
| 27 | term.setCursorPos(1,y) | |
| 28 | end | |
| 29 | ||
| 30 | while true do | |
| 31 | term.clear() | |
| 32 | term.setCursorPos(1,1) | |
| 33 | print("Train Identifier\n")
| |
| 34 | local looping = true | |
| 35 | local trainID = "Pending" | |
| 36 | local x,y = term.getCursorPos() | |
| 37 | while looping do | |
| 38 | screenClear(y) | |
| 39 | print("Train ID = "..trainID)
| |
| 40 | local event = {os.pullEvent()}
| |
| 41 | if event[1] == "redstone" then | |
| 42 | print("Train Arrived")
| |
| 43 | print("Setting ID to: "..trainID)
| |
| 44 | local red = redstone.getBundledInput("left")
| |
| 45 | trainID = getID(red) | |
| 46 | elseif event[1] == "modem_message" then | |
| 47 | messageHandler(event, trainID) | |
| 48 | looping = false | |
| 49 | end | |
| 50 | end | |
| 51 | end |