107 posts
Posted 30 September 2012 - 11:04 AM
I use a repeat until slope for my turtle and want it to select the next inventory slot after 2 loops. It uses 32 Blocks per loop and after 2 the slot is empty, so it should select the second and so on. How to do it?
175 posts
Posted 30 September 2012 - 12:56 PM
If you have an incrementing variable (eg. for i=n,m), you can do "if i%2 == 0 then", which will then be true every other loop.
107 posts
Posted 30 September 2012 - 01:08 PM
What is a incrementing variable? Can you explain it?
107 posts
Posted 30 September 2012 - 01:30 PM
Okay I make an example, lets say this is the code:
local i=1
x=tonumber(io.read())
turtle.select(1)
repeat
for f=1,32 do
turtle.placeDown()
turtle.up
end
i=i+1
until i == x
Whats the code I would have to add?
Edit: It would also be better if it automatically detects when the slot is empty and switches to the next, how to do it?
818 posts
Posted 30 September 2012 - 03:02 PM
local i=1
local slotNum
x=tonumber(io.read())
turtle.select(1)
repeat
for f=1,32 do
if f%2 == 0 then
slotNum = slotnum + 1
turtle.select(slotNum)
end
turtle.placeDown()
turtle.up()
end
i=i+1
until i == x
818 posts
Posted 30 September 2012 - 03:04 PM
local i=1
local slotNum
x=tonumber(io.read())
turtle.select(1)
repeat
for f=1,32 do
while turtle.getItemCount() == 0 do
slotNum = slotnum + 1
turtle.select(slotNum)
end
turtle.placeDown()
turtle.up()
end
i=i+1
until i == x
for detecting empty slots.
107 posts
Posted 30 September 2012 - 03:05 PM
Thank you very much! But sorry for me asking so much, this is the real code from me:
It would have to check after every blockplacement, should I just add this code after every turtle.place() ?
turtle.up()
turtle.select(1)
local i = 1
write("How high should the dice be: ")
x = tonumber(io.read())
turtle.forward()
--walls
for f=1,x do
for a=1,8 do
turtle.forward()
turtle.placeDown()
end
turtle.turnRight()
for b=1,8 do
turtle.forward()
turtle.placeDown()
end
turtle.turnRight()
for c=1,8 do
turtle.forward()
turtle.placeDown()
end
turtle.turnRight()
for d=1,8 do
turtle.forward()
turtle.placeDown()
end
turtle.turnRight()
turtle.up()
end
--Turtle going down when finished
turtle.back()
while not turtle.detectDown() do
turtle.down()
end
818 posts
Posted 30 September 2012 - 03:16 PM
put it before blockplace, that way you know it will always select before it tries to place down. makes it more idiot proof
107 posts
Posted 30 September 2012 - 03:22 PM
Okay thanks, but now it is expecting a number at this line:
(I believe it wants the slotnumber in the getItemCount() )
while turtle.getItemCount() == 0 do
What could I do ?
818 posts
Posted 30 September 2012 - 04:02 PM
oh, just put slotNum in there.
and when you define slotNum, define it to 1, so you won't get a slot 0 doesn't exist bug.
107 posts
Posted 30 September 2012 - 04:05 PM
Thank you! I already tried but made a mistake. Now it works without any problems.