Advertisement
PinSeventy

Recon Turtle Loop

Jul 24th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | None | 0 0
  1. --[[
  2. THE RECON TURTLE
  3. ----------------
  4. The goal of this program is to use a wireless turtle to 'scout' out
  5. an area using comparison functions everytime it moves.  It uses
  6. remote-control style movement, then runs through a detection loop
  7. which identifies blocks in the surrounding area by comparing them to
  8. blocks in it's own inventory.
  9. ]]--
  10.  
  11.  
  12. --VARIABLE DELCARATIONS
  13. local inventory = {}
  14. for i=1, 16 do
  15.     inventory[i] = 'block'
  16. end
  17. local userInput = 'nil'
  18. local match = false
  19.  
  20.  
  21. --FUNCTION DECLARATIONS
  22.  
  23. function inputInventory()       --Gathers blocks in inventory w/ names for identification
  24.     shell.run("clear")
  25.     print("         INVENTORY MANAGEMENT         ")
  26.     print("--------------------------------------")
  27.     for slot=1, 16 do
  28.         print("Place a block in slot"..slot..".")
  29.         while turtle.getItemCount(slot) == 0 do
  30.             os.pullEvent("turtle_inventory")
  31.         end
  32.         print("Enter the name of the block:")
  33.         inventory[slot] = read()
  34.         print("ID'd "..inventory[slot].." in slot "..[slot]..".")
  35.     end
  36. end
  37.  
  38. function compare(side)      --Compares [side] to inventory for identification; returns name if ID'd
  39.     match = false
  40.     if side == "front" then
  41.         while match == false do
  42.             for slot=1, 16 do
  43.                 turtle.select(slot)
  44.                 if turtle.compare() then
  45.                     return inventory[slot]
  46.                     match = true
  47.                 end
  48.             end
  49.         end
  50.     elseif side == "left" then
  51.         turtle.turnLeft()
  52.         while match == false do
  53.             for slot=1, 16 do
  54.                 turtle.select(slot)
  55.                 if turtle.compare() then
  56.                     turtle.turnRight()
  57.                     return inventory[slot]
  58.                     match = true
  59.                 end
  60.             end
  61.         end
  62.     elseif side == "right" then
  63.         turtle.turnRight()
  64.         while match == false do
  65.             for slot=1, 16 do
  66.                 turtle.select(slot)
  67.                 if turtle.compare() then
  68.                     turtle.turnLeft()
  69.                     return inventory[slot]
  70.                     match = true
  71.                 end
  72.             end
  73.         end
  74.     elseif side == "down" then
  75.         while match == false do
  76.             for slot=1, 16 do
  77.                 turtle.select(slot)
  78.                 if turtle.compareDown() then
  79.                     return inventory[slot]
  80.                     match = true
  81.                 end
  82.             end
  83.         end
  84.     elseif side == "up" then
  85.         while match == false do
  86.             for slot=1, 16 do
  87.                 turtle.select(slot)
  88.                 if turtle.compareUp() then
  89.                     return inventory[slot]
  90.                     match = true
  91.                 end
  92.             end
  93.         end
  94.     elseif side == "back" then
  95.         turtle.turnRight()
  96.         turtle.turnRight()
  97.         while match == false do
  98.             for slot=1, 16 do
  99.                 turtle.select(slot)
  100.                 if turtle.compare() then
  101.                     turtle.turnRight()
  102.                     turtle.turnRight()
  103.                     return inventory[slot]
  104.                     match = true
  105.                 end
  106.             end
  107.         end
  108.     end
  109. end
  110.  
  111.  
  112.  
  113. --EXECUTION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement