Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- THE RECON TURTLE
- ----------------
- The goal of this program is to use a wireless turtle to 'scout' out
- an area using comparison functions everytime it moves. It uses
- remote-control style movement, then runs through a detection loop
- which identifies blocks in the surrounding area by comparing them to
- blocks in it's own inventory.
- ]]--
- --VARIABLE DELCARATIONS
- local inventory = {}
- for i=1, 16 do
- inventory[i] = 'block'
- end
- local userInput = 'nil'
- local match = false
- --FUNCTION DECLARATIONS
- function inputInventory() --Gathers blocks in inventory w/ names for identification
- shell.run("clear")
- print(" INVENTORY MANAGEMENT ")
- print("--------------------------------------")
- for slot=1, 16 do
- print("Place a block in slot"..slot..".")
- while turtle.getItemCount(slot) == 0 do
- os.pullEvent("turtle_inventory")
- end
- print("Enter the name of the block:")
- inventory[slot] = read()
- print("ID'd "..inventory[slot].." in slot "..[slot]..".")
- end
- end
- function compare(side) --Compares [side] to inventory for identification; returns name if ID'd
- match = false
- if side == "front" then
- while match == false do
- for slot=1, 16 do
- turtle.select(slot)
- if turtle.compare() then
- return inventory[slot]
- match = true
- end
- end
- end
- elseif side == "left" then
- turtle.turnLeft()
- while match == false do
- for slot=1, 16 do
- turtle.select(slot)
- if turtle.compare() then
- turtle.turnRight()
- return inventory[slot]
- match = true
- end
- end
- end
- elseif side == "right" then
- turtle.turnRight()
- while match == false do
- for slot=1, 16 do
- turtle.select(slot)
- if turtle.compare() then
- turtle.turnLeft()
- return inventory[slot]
- match = true
- end
- end
- end
- elseif side == "down" then
- while match == false do
- for slot=1, 16 do
- turtle.select(slot)
- if turtle.compareDown() then
- return inventory[slot]
- match = true
- end
- end
- end
- elseif side == "up" then
- while match == false do
- for slot=1, 16 do
- turtle.select(slot)
- if turtle.compareUp() then
- return inventory[slot]
- match = true
- end
- end
- end
- elseif side == "back" then
- turtle.turnRight()
- turtle.turnRight()
- while match == false do
- for slot=1, 16 do
- turtle.select(slot)
- if turtle.compare() then
- turtle.turnRight()
- turtle.turnRight()
- return inventory[slot]
- match = true
- end
- end
- end
- end
- end
- --EXECUTION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement