This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Neopherus's profile picture

[LUA] Transfer command with multiple slots

Started by Neopherus, 02 February 2013 - 07:33 AM
Neopherus #1
Posted 02 February 2013 - 08:33 AM
Hi again.
Since this forum *actually* contains "pros" I figured I'd ask here again.

I made a program that makes a safe tunnel through the nether for me(digging a 2x1 tunnel and placing blocks when there is a hole that shouldn't be, to avoid lava.).
Problems arise when my turtle passes through a large open area though, which makes him run out of blocks but still tries to complete the "todo", so my question is:

Can someone please be so kind as to tell me how to make him check his active slot *and* if empty transfer from any inactive slot to slot(1)?

I checked the wiki, and considered trying "for x = 2, 16 do", but I have no idea if/how that will actually work.
Will I need to use both "compare" and "transfer" here, or is there a simpler way?
If an easy way, please supply the correct wiki link or the actual function line.

Thank you all for your awesomeness!
Kingdaro #2
Posted 02 February 2013 - 08:42 AM
That "for x=2, 16" loop will come handy here. (though I usually use i instead of x, or slot would be a better name in this case.) Simply loop through all of the slots except the first, and if they contain anything, transfer them to the first slot.

for slot=2, 16 do
  if turtle.getItemCount(slot) > 0 then
    turtle.select(slot)
    turtle.transferTo(1)
  end
end
Neopherus #3
Posted 02 February 2013 - 09:06 AM
That "for x=2, 16" loop will come handy here. (though I usually use i instead of x, or slot would be a better name in this case.) Simply loop through all of the slots except the first, and if they contain anything, transfer them to the first slot.

for slot=2, 16 do
  if turtle.getItemCount(slot) > 0 then
	turtle.select(slot)
	turtle.transferTo(1)
  end
end

I used x as an "unnamed variable" since I use "i" as todo. :P/> But that looks like it would work!
I'm guessing that

if turtle.getItemCount(1) = 0
should be the first line, though?
Anywho: thanks alot man! :)/> Will try it out.

edit: oh btw. Any way to make that a "while true" function?
Neopherus #4
Posted 02 February 2013 - 11:08 AM
forget about the "while true" loop question, I can make a function that checks all slots and add it to each integer of the program. However, I do not know if I have to write the "get.ItemCount" check for every single slot or if there is an easier way. (messed around with loops and the whole 2, 16 thing, but it didn't seem to work).
Any further pointers, oh master?