Advertisement
Phishphan420

elevatorControl

Sep 7th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.11 KB | None | 0 0
  1. local senderID, destination, dist, currLocation, numMoves, direction
  2. currLocation = "PULSAR"
  3.  
  4. --[[
  5. commands = {
  6.     ["up"] = colors.white,          -- if they type a direction
  7.     ["down"] = colors.red,      -- return the cable color
  8.     ["left"] = colors.black,            -- corresponding to that
  9.     ["right"] = colors.green,       -- engine
  10.     ["forward"] = colors.blue,
  11.     ["backward"] = colors.brown,
  12.     ["u"] = colors.white,           -- same thing, this just lets
  13.     ["d"] = colors.red,         -- people type in shortcuts
  14.     ["l"] = colors.black,           -- like "f" instead of "forward"
  15.     ["r"] = colors.green,
  16.     ["f"] = colors.blue,
  17.     ["b"] = colors.brown,
  18. }
  19. --]]
  20.  
  21.  
  22. local destinations = {} --initialize the destination array which lists all destinations
  23.  
  24. destinations["PULSAR"] = "8"
  25. destinations["control"] = "14"
  26. destinations["surface"] = "29"
  27.  
  28.  
  29. -- takes a redstone cable color and a count, and triggers the engine connected
  30. -- to aColor cable, aCount times
  31. function move(aColor, aCount)              
  32.     for i=1, aCount do                  -- count up from 1 to aCount
  33.         rs.setBundledOutput("back",aColor)      -- turn the cable on
  34.         sleep(.2)                       -- wait 0.2 sec
  35.         rs.setBundledOutput("back",0)           -- turn the cable off
  36.         sleep(.6)                       -- give the engines time to get back in place
  37.     end
  38. end
  39.  
  40. -- This function will prompt the user for a direction and count
  41. function waitForCommand()
  42.     while true do                       -- keep looping through this constantly
  43.         senderID, destination, dist = rednet.receive()
  44.         print("Recieved move command ("..destination..") from ("..senderID..")")
  45.             if destination == "controlRoomPULSAR" then
  46.                 moveToControlFromPULSAR()
  47.                 currLocation = "control"
  48.             elseif destination =="surfacePULSAR" then
  49.                 moveToSurfaceFromPULSAR()
  50.                 currLocation = "surface"
  51.             elseif destination == "controlRoomSurface" then
  52.                 moveToControlFromSurface()
  53.                 currLocation = "control"
  54.             elseif destination == "PULSARSurface" then
  55.                 moveToPULSARFromSurface()
  56.                 currLocation = "PULSAR"
  57.             elseif destination == "surfaceControl" then
  58.                 moveToSurfaceFromControl()
  59.                 currLocation = "surface"
  60.             elseif destination == "PULSARControl" then
  61.                 moveToPULSARFromControl()
  62.                 currLocation = "PULSAR"
  63.             elseif destination == "call" then              
  64.                 if (currLocation == "control" and senderID == "175") then
  65.                     moveToPULSARFromControl()
  66.                     currLocation = "PULSAR"
  67.                 elseif (currLocation == "surface" and senderID == "175") then
  68.                     moveToPULSARFromSurface()
  69.                     currLocation = "PULSAR"
  70.                 elseif (currLocation == "PULSAR" and senderID == "175") then
  71.                     currLocation = "PULSAR"
  72.                 elseif (currLocation == "PULSAR" and senderID == "178") then
  73.                     moveToControlFromPULSAR()
  74.                     currLocation = "control"
  75.                 elseif (currLocation == "surface" and senderID == "178") then
  76.                     moveToControlFromSurface()
  77.                     currLocation = "control"
  78.                 elseif (currLocation == "control" and senderID == "178") then
  79.                     currLocation = "control"
  80.                 elseif (currLocation == "PULSAR" and senderID == "192") then
  81.                     moveToSurfaceFromPULSAR()
  82.                     currLocation = "surface"
  83.                 elseif (currLocation == "control" and senderID =="192") then
  84.                     moveToSurfaceFromControl()
  85.                     currLocation = "surface"
  86.                 elseif (currLocation == "surface" and senderID == "192") then
  87.                     currLocation = "surface"
  88.                 end
  89.             end
  90. --      moveToDestination(currLocation, destination[1])
  91.         print("Elevator's current location is ("..currLocation..")")
  92.     end
  93. end
  94.  
  95. --[[
  96. function moveToDestination(aOrigin, aDestination)
  97.     numMoves = aDestination-aOrigin
  98.     if numMoves < 0 then
  99.         direction = colors.red
  100.     elseif numMoves > 0 then
  101.         direction = colors.white
  102.     end
  103.     move(direction, numMoves)
  104.     currLocation = aOrigin
  105. end
  106. --]]
  107.  
  108. function moveToControlFromPULSAR()
  109.     move(colors.white, 6)
  110. end
  111.  
  112. function moveToSurfaceFromPULSAR()
  113.     move(colors.white, 21)
  114. end
  115.  
  116. function moveToSurfaceFromControl()
  117.     move(colors.white, 15)
  118. end
  119.  
  120. function moveToPULSARFromControl()
  121.     move(colors.red, 6)
  122. end
  123.  
  124. function moveToControlFromSurface()
  125.     move(colors.red, 15)
  126. end
  127.  
  128. function moveToPULSARFromSurface()
  129.     move(colors.red, 21)
  130. end
  131.  
  132. rednet.open("top")
  133. waitForCommand()                    -- this is the initial call to the waitForCommand function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement