26 posts
Posted 09 July 2014 - 11:12 PM
Hey guys, I'm having a hard time figuring out how to use the boolean return from the turtle function
turtle.drop() which places items into an inventory. It returns
false if the inventory is full, which I am interested in utilizing, but I'm not really sure how to do so.
I'm just confused if the following code will drop items if the inventory is not full, and also return false if it is full, setting
chestFull to
true.
if not turtle.drop() then
chestFull = true
end
If I'm just being a dolt and this does that, please let me know. If you have an idea of how to make this do what I want it to, also let me know!
Much appreciated,
-ReconTurtle
3057 posts
Location
United States of America
Posted 09 July 2014 - 11:38 PM
That does do what you are thinking, but you can simply do this:
chestFull = not turtle.drop() --#not inverts a boolean value. therefore, true becomes false, and false becomes true.
26 posts
Posted 09 July 2014 - 11:48 PM
So if I just run chestFull = not turtle.drop() then it will drop them into the inventory, not just store the result to chestFull?
3057 posts
Location
United States of America
Posted 10 July 2014 - 12:13 AM
Yep. turtle.drop() runs before returning, just like any function.
26 posts
Posted 10 July 2014 - 02:56 AM
I got it working with your help, thanks! Sorry for all the questions, I was unable to test it at the time, but was still writing the code.
26 posts
Posted 10 July 2014 - 03:20 AM
Nope, not actually working as I thought it was. Here's the bit of code that's not working for me:
function deposit()
turtle.turnRight()
turtle.turnRight()
for slot=1,16,1 do
if turtle.getItemCount(slot) ~= 0 then
print("Depositing item in slot "..slot)
chestFull = not turtle.drop()
end
end
turtle.select(1)
turtle.turnRight()
turtle.turnRight()
print("Cobble Mined: "..runningTotal)
end
No matter how much is in any item slot,
chestFull is always being set to true, which should definitely not be happening. What am I missing here?Edit: From the bit of de-bugging I've done, chestFull = not turtle.drop() is returning, but it is not depositing items.
Edited on 10 July 2014 - 01:24 AM
3057 posts
Location
United States of America
Posted 10 July 2014 - 03:53 AM
try adding turtle.select( slot ) before you drop all the items in the current slot.
26 posts
Posted 10 July 2014 - 04:33 AM
Oh duh, thank you for pointing that out. +1.