Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local senderID, destination, dist, currLocation, numMoves, direction
- currLocation = "PULSAR"
- --[[
- commands = {
- ["up"] = colors.white, -- if they type a direction
- ["down"] = colors.red, -- return the cable color
- ["left"] = colors.black, -- corresponding to that
- ["right"] = colors.green, -- engine
- ["forward"] = colors.blue,
- ["backward"] = colors.brown,
- ["u"] = colors.white, -- same thing, this just lets
- ["d"] = colors.red, -- people type in shortcuts
- ["l"] = colors.black, -- like "f" instead of "forward"
- ["r"] = colors.green,
- ["f"] = colors.blue,
- ["b"] = colors.brown,
- }
- --]]
- local destinations = {} --initialize the destination array which lists all destinations
- destinations["PULSAR"] = "8"
- destinations["control"] = "14"
- destinations["surface"] = "29"
- -- takes a redstone cable color and a count, and triggers the engine connected
- -- to aColor cable, aCount times
- function move(aColor, aCount)
- for i=1, aCount do -- count up from 1 to aCount
- rs.setBundledOutput("back",aColor) -- turn the cable on
- sleep(.2) -- wait 0.2 sec
- rs.setBundledOutput("back",0) -- turn the cable off
- sleep(.6) -- give the engines time to get back in place
- end
- end
- -- This function will prompt the user for a direction and count
- function waitForCommand()
- while true do -- keep looping through this constantly
- senderID, destination, dist = rednet.receive()
- print("Recieved move command ("..destination..") from ("..senderID..")")
- if destination == "controlRoomPULSAR" then
- moveToControlFromPULSAR()
- currLocation = "control"
- elseif destination =="surfacePULSAR" then
- moveToSurfaceFromPULSAR()
- currLocation = "surface"
- elseif destination == "controlRoomSurface" then
- moveToControlFromSurface()
- currLocation = "control"
- elseif destination == "PULSARSurface" then
- moveToPULSARFromSurface()
- currLocation = "PULSAR"
- elseif destination == "surfaceControl" then
- moveToSurfaceFromControl()
- currLocation = "surface"
- elseif destination == "PULSARControl" then
- moveToPULSARFromControl()
- currLocation = "PULSAR"
- elseif destination == "call" then
- if (currLocation == "control" and senderID == "175") then
- moveToPULSARFromControl()
- currLocation = "PULSAR"
- elseif (currLocation == "surface" and senderID == "175") then
- moveToPULSARFromSurface()
- currLocation = "PULSAR"
- elseif (currLocation == "PULSAR" and senderID == "175") then
- currLocation = "PULSAR"
- elseif (currLocation == "PULSAR" and senderID == "178") then
- moveToControlFromPULSAR()
- currLocation = "control"
- elseif (currLocation == "surface" and senderID == "178") then
- moveToControlFromSurface()
- currLocation = "control"
- elseif (currLocation == "control" and senderID == "178") then
- currLocation = "control"
- elseif (currLocation == "PULSAR" and senderID == "192") then
- moveToSurfaceFromPULSAR()
- currLocation = "surface"
- elseif (currLocation == "control" and senderID =="192") then
- moveToSurfaceFromControl()
- currLocation = "surface"
- elseif (currLocation == "surface" and senderID == "192") then
- currLocation = "surface"
- end
- end
- -- moveToDestination(currLocation, destination[1])
- print("Elevator's current location is ("..currLocation..")")
- end
- end
- --[[
- function moveToDestination(aOrigin, aDestination)
- numMoves = aDestination-aOrigin
- if numMoves < 0 then
- direction = colors.red
- elseif numMoves > 0 then
- direction = colors.white
- end
- move(direction, numMoves)
- currLocation = aOrigin
- end
- --]]
- function moveToControlFromPULSAR()
- move(colors.white, 6)
- end
- function moveToSurfaceFromPULSAR()
- move(colors.white, 21)
- end
- function moveToSurfaceFromControl()
- move(colors.white, 15)
- end
- function moveToPULSARFromControl()
- move(colors.red, 6)
- end
- function moveToControlFromSurface()
- move(colors.red, 15)
- end
- function moveToPULSARFromSurface()
- move(colors.red, 21)
- end
- rednet.open("top")
- waitForCommand() -- this is the initial call to the waitForCommand function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement