Posted 30 November 2013 - 12:43 PM
I'm a beginner at turtle coding (Programming?) and was wondering if there was a way to shorten this piece, for future purposes. It does work, but using it in several programs and typing it each time is insanely tedious. It's meant to check if the item count in slot 1 is empty. If not, it doesn't do anything. If so, it moves items in all slots to slot one.
Also, for context purposes, I'm using it in this program. It creates a bridge until it detects a solid piece of land underneath it.
Spoiler
function fill()
if turtle.getItemCount(1) == 0 then
turtle.select(2)
turtle.transferTo(1)
turtle.select(3)
turtle.transferTo(1)
turtle.select(4)
turtle.transferTo(1)
turtle.select(5)
turtle.transferTo(1)
turtle.select(6)
turtle.transferTo(1)
turtle.select(7)
turtle.transferTo(1)
turtle.select(8)
turtle.transferTo(1)
turtle.select(9)
turtle.transferTo(1)
turtle.select(10)
turtle.transferTo(1)
turtle.select(11)
turtle.transferTo(1)
turtle.select(12)
turtle.transferTo(1)
turtle.select(13)
turtle.transferTo(1)
turtle.select(14)
turtle.transferTo(1)
turtle.select(15)
turtle.transferTo(1)
turtle.select(16)
turtle.transferTo(1)
turtle.select(1)
end
end
Also, for context purposes, I'm using it in this program. It creates a bridge until it detects a solid piece of land underneath it.
Spoiler
local dis = 0
local pln = 0
function fill()
if turtle.getItemCount(1) == 0 then
turtle.select(2)
turtle.transferTo(1)
turtle.select(3)
turtle.transferTo(1)
turtle.select(4)
turtle.transferTo(1)
turtle.select(5)
turtle.transferTo(1)
turtle.select(6)
turtle.transferTo(1)
turtle.select(7)
turtle.transferTo(1)
turtle.select(8)
turtle.transferTo(1)
turtle.select(9)
turtle.transferTo(1)
turtle.select(10)
turtle.transferTo(1)
turtle.select(11)
turtle.transferTo(1)
turtle.select(12)
turtle.transferTo(1)
turtle.select(13)
turtle.transferTo(1)
turtle.select(14)
turtle.transferTo(1)
turtle.select(15)
turtle.transferTo(1)
turtle.select(16)
turtle.transferTo(1)
turtle.select(1)
end
end
turtle.forward()
while turtle.detectDown() == false do
turtle.down()
turtle.turnLeft()
turtle.place()
fill()
pln = pln + 1
turtle.turnRight()
turtle.turnRight()
turtle.place()
pln = pln + 1
fill()
turtle.up()
turtle.placeDown()
pln = pln + 1
fill()
turtle.turnLeft()
turtle.forward()
dis = dis + 1
print(pln.. "...")
end
print("Bridged ".. dis .." blocks, using "..pln.."blocks.")