all I want is a turtle that will fill in blocks in a straight line for a certain distance. how would I right that code
I'm a noob in programming, but I think that user input would be:
i = i - 1 (not sure if that is necessary)
local args = {...}
local length
if (args[1] == nil) then
length = 10
else
length = args[1]
end
for i=0, length do
while (not turtle.forward()) do
if (turtle.detect()) then
turtle.dig()
else
turtle.attack()
end
end
turtle.placeDown()
end
term.write("How many blocks to fill: ")
blocks = read()
turtle.select(1)
for i = 1, blocks do
turtle.placeDown()
turtle.forward()
end
-- Checks if slot is empty, and moves to next slot
i = 1
while turtle.getItemCount() <=0 do
i = i + 1
turtle.select(i)
end
turtle.placeDown()
I know I'm nitpicking, so I apologise for this, but can't you have i start at 1 since 1 is the first slot? Or am I wrong and it goes from 0 to 8?One thing that needs to be added is having the turtle change slots, otherwise it can only place a line of 64. Something like:
Code:i = 0 while turtle.place() == false do i = i + 1 turtle.select(i) end turtle.placeDown()
I know I'm nitpicking, so I apologise for this, but can't you have i start at 1 since 1 is the first slot? Or am I wrong and it goes from 0 to 8?
In that case, it would keep changing slots if there was a block under it. You can use turtle.getSlotCount() (I think that's what it's called) to check the count and use an if then statement to say when the slot is less than 0 to change the slot.One thing that needs to be added is having the turtle change slots, otherwise it can only place a line of 64. Something like:
Code:i = 1 while turtle.place() == false do i = i + 1 turtle.select(i) end turtle.placeDown()
Edit: Fixed to fit Lua