Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Calls lift
- --CONST
- POS = 0 --Number of blocks between position 0 and the level we're at (if negative, means we're below level 0)
- M_SIDE = "back" --Modem side
- R_SIDE = "bottom" --Side we get lift signal from
- B_SIDE = "left" --Side we get button signal from
- CHANNEL = 1 --Channel to send calls to
- --
- --FUNC
- function waitForAnswer() --Waits for the lift to answer
- local event
- local timer = os.startTimer(1) --Time to wait for an answer
- while true do
- event = {os.pullEvent()}
- if event[1] == "modem_message" and event[5] == "pong" then
- return true --The lift got our message
- elseif event[1] == "timer" and event[2] == timer then
- return false --The lift did not have time to answer (we're assuming it didn't get our message)
- end
- end
- end
- --
- --MAIN
- --Wrapping and opening modem
- local modem = peripheral.wrap(M_SIDE)
- modem.open(CHANNEL)
- --Main loop
- while true do
- os.pullEvent("redstone") --Waiting for a redstone state change (there is no parameter)
- if rs.getInput(R_SIDE) then rs.setOutput(B_SIDE, false) end --Got signal from lift, we turn the lamp off
- if rs.getInput(B_SIDE) and not rs.getInput(R_SIDE) then --Got signal from button, and if the lift is not already there
- --We send position to lift
- print("Calling elevator to position "..POS)
- modem.transmit(CHANNEL, CHANNEL, POS)
- if waitForAnswer() then --If the lift got the message
- print("Elevator incomming")
- rs.setOutput(B_SIDE, true) --We keep light on to say it's comming
- else --Otherwise we do nothing, the lamp will turn off
- print("Failed to call elevator")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement