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

How to check turtle slots before continuing?

Started by teg0r, 13 April 2014 - 12:25 AM
teg0r #1
Posted 13 April 2014 - 02:25 AM
Hi! Im trying to make program for craft turtle but today is first time im actually trying to make my own program.

So here is the problem, i got this piece of code:
while true do
turtle.select(11)
turtle.suckUp()
turtle.select(10)
turtle.suckUp()
turtle.select(9)
turtle.suckUp()
turtle.select(7)
turtle.suckUp()
turtle.select(6)
turtle.suckUp()
turtle.select(5)
turtle.suckUp()
turtle.select(3)
turtle.suckUp()
turtle.select(2)
turtle.suckUp()
turtle.select(1)
turtle.suckUp()
turtle.craft()
turtle.dropDown()
sleep(0.1)
end

Currently im making compressed cobblestone with turtles with chest on top with cobblestones and chest below turtle to put compressed cobble in. But the problem is that sometimes chest goes empty and some inventory slots are left empty on turtle and it makes stuff like slabs, walls or whatever.

So id like to know how to make it like that it checks that all those 9 slots have anything in them before it continues to turtle.craft()
I have read tutorials and tried to google it but cant find help for this :(/>

Thanks and sorry for possible typos :D/>
Bomb Bloke #2
Posted 13 April 2014 - 03:13 AM
The "turtle.suckUp()" command not only attempts to suck items into the turtle's inventory, it returns either true or false depending on whether it was successful or not (kinda like how read() returns whatever the user types in, if you're familiar with that).

So, if instead of this:

turtle.suckUp()

… we do this:

while not turtle.suckUp() do end

… then that defines a loop which does nothing but call "turtle.suckUp()" over and over again until the first time it returns true.
teg0r #3
Posted 13 April 2014 - 03:26 AM
Oh nice that was easier than i expected.
Thanks alot for quick and simple answer :P/>
TimTheRedstoner #4
Posted 13 April 2014 - 04:47 AM
why don't you use


if turtle.getItemCount(turtle.getSelectedSlot()) < 0 then
print("Not Enough Items!")
for i = turtle.select(1, 16) do
turtle.dropUp()
end
else
craft()
end

Also Bomb Bloke i don't think that would work for his purpose. Cause he wants it to have the correct amount in each slot, not just if it can gather some items.
Edited on 13 April 2014 - 03:20 AM
Bomb Bloke #5
Posted 13 April 2014 - 05:47 AM
Oh, I know he'd likely want to make further edits once he sorted that issue - I just figure he may be able to work them out for himself.

That was also the mentality behind your code sample, right? ;)/>

(Edit: That said, if you have any related questions teg0r, don't hesitate to ask - I just don't want to spoil your fun.)
Edited on 13 April 2014 - 05:19 AM
axel.codeFail() #6
Posted 15 April 2014 - 03:47 AM

turtle.dropUp()

Does turtle.dropUp() work? Last time I tried ( in Minecraft 1.6.4 ) it either didn't work, or I did it wrong.
Bomb Bloke #7
Posted 15 April 2014 - 04:07 AM
It depends on what's above the turtle. IIRC, Factorisation barrels for eg can only be filled from the top.