Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- * modem side here
- rednet.open("top")
- -- * current floor - might not be accurate
- -- * since you have three computers (the ones that call the elevator),
- -- you could use some GPS code to determine the current floor
- local current = 1
- local floorIDs = {
- -- * ["sender IDs in strings"] = the floors they are on
- -- * you can expand this table further
- ["40"] = 1,
- ["41"] = 2,
- ["42"] = 3,
- }
- local gotoFloor = function(target)
- repeat
- if current > target then -- target is lower ...
- for i = 1, 12 do -- ... so go down
- rs.setOutput("right", true)
- sleep(0.5)
- rs.setOutput("right", false)
- sleep(0.5)
- rs.setOutput("back", true)
- sleep(0.5)
- rs.setOutput("back", false)
- sleep(0.5)
- end
- current = current - 1
- elseif current < target then -- target is higher ...
- for i = 1, 12 do -- ... so go up
- rs.setOutput("left", true)
- sleep(0.5)
- rs.setOutput("left", false)
- sleep(0.5)
- rs.setOutput("buttom", true)
- sleep(0.5)
- rs.setOutput("buttom", false)
- sleep(0.5)
- end
- current = current + 1
- end
- until target == current -- we've reached the target
- end
- while true do
- local eventData = {os.pullEvent()}
- -- * now eventData[2] is the sender and eventData[3] is the message
- if eventData[1] == "rednet_message" and eventData[3] == "elevator_call" then
- -- * every computer will send only "elevator_call"
- local target = floorIDs[tostring(eventData[2])]
- if target then
- -- * call gotoFloor only if target is not nil
- -- * that would mean that a computer which is not in the floorIDs table
- -- above sent the "elevator_call" message
- gotoFloor(target)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement