Jump to content




Select next slot every other loop / Switch to next slot when slot is empty?


  • You cannot reply to this topic
10 replies to this topic

#1 Klausar

  • Members
  • 110 posts

Posted 30 September 2012 - 10: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?

#2 robhol

  • Members
  • 182 posts

Posted 30 September 2012 - 11:56 AM

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.

#3 Klausar

  • Members
  • 110 posts

Posted 30 September 2012 - 12:08 PM

What is a incrementing variable? Can you explain it?

#4 Klausar

  • Members
  • 110 posts

Posted 30 September 2012 - 12: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?

#5 Doyle3694

  • Members
  • 815 posts

Posted 30 September 2012 - 02: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


#6 Doyle3694

  • Members
  • 815 posts

Posted 30 September 2012 - 02: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.

#7 Klausar

  • Members
  • 110 posts

Posted 30 September 2012 - 02: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


#8 Doyle3694

  • Members
  • 815 posts

Posted 30 September 2012 - 02: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

#9 Klausar

  • Members
  • 110 posts

Posted 30 September 2012 - 02: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 ?

#10 Doyle3694

  • Members
  • 815 posts

Posted 30 September 2012 - 03: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.

#11 Klausar

  • Members
  • 110 posts

Posted 30 September 2012 - 03:05 PM

Thank you! I already tried but made a mistake. Now it works without any problems.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users