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

The turtle sucks more than what it needs...

Started by Furest_, 06 August 2014 - 08:56 PM
Furest_ #1
Posted 06 August 2014 - 10:56 PM
Hello,
It's me again with an other bug again for posting again!

I've setup a tree farm and at one point the turtle needs to refuel the 3 stacks of bone meal.
Since the amount to reload depends of the bone meal consumed, i've written this script to make the turtle sucks just what it needs. But I don't know why it always takes too much.
Sometimes it even makes me a stack of 123 items and when I click on it it became just one item (not shown in the video)

Here's my code:

bonea = turtle.getItemSpace(5)
boneb = turtle.getItemSpace(6)
bonec = turtle.getItemSpace(7)
total = bonea+boneb+bonec
turtle.select(5)
print("total:"..total)
while total > 64 do
turtle.suck(64)
print("suck 64")
total = total - 64
print("reste:"..total)
sleep(2)
end
turtle.suck(total)
print("suck "..total)
print("final:"..total)

It sucks just 3 times. the first time it takes 64 (since the maximum amount we can suck in one full stack) the second one too and the third time it is supposed to take 61.
But I have a bunch of bone meal I haven't even asked for…

Is it a bug or my code which is wrong? I think it's a bug but… who knows?


Video:
[media]http://www.youtube.com/watch?v=IDNHpQqhT_I[/media]
Furest
Edited on 07 August 2014 - 07:58 AM
Cranium #2
Posted 06 August 2014 - 11:28 PM
I believe it's because you're using turtle.getItemSpace() which gets the amount of free space remaining, instead of turtle.getItemCount(), which gets the total of items stored.
Furest_ #3
Posted 06 August 2014 - 11:38 PM
I think no, because I get the free space and then refill my inventory with "freespace" items.
So I have a sum of all the free space for my 3 slots of bone meal and then I reload.
Is it wrong?
Furest_ #4
Posted 07 August 2014 - 08:14 PM
Hey, what happened to the two lasts topics?
Lyqyd #5
Posted 07 August 2014 - 08:31 PM
They were hidden. We're generally trying to avoid posting the specifics of the duplication glitch. The problem has been posted a fair bit and the reproduction instructions have been passed on to dan. In the meantime, we can try to help come up with a workaround for your script, but the underlying bug will have to be fixed by dan.
Furest_ #6
Posted 07 August 2014 - 10:08 PM
OK, no problem I understand you don't want this kind of bug to be seen :)/>
MR_nesquick #7
Posted 07 August 2014 - 11:40 PM
can't see the problem in your code.
is there something else that sucks after your running this code?


you can try this. if it's still happening there is something else that sucks bone meal
for i = 5,7 do
  turtle.select(i)
  turtle.suck(turtle.getItemSpace(i))
end
flaghacker #8
Posted 08 August 2014 - 07:50 AM
can't see the problem in your code.
is there something else that sucks after your running this code?


you can try this. if it's still happening there is something else that sucks bone meal
for i = 5,7 do
  turtle.select(i)
  turtle.suck(turtle.getItemSpace(i))
end

Further testing has shown that the problem is a duplication glitch, as Liquid said.
Furest_ #9
Posted 17 August 2014 - 01:26 PM
Hi,
I've finally found a kind of solution top the problem.
By sucking the items 1 by 1 it seems to work properly.
So I've done like this:


for i = 5,7 do
turtle.select(i)
while turtle.getItemSpace(i) > 0 do
  turtle.suck(1)
 end
end

Hope it help for many others than me :)/>
Edited on 17 August 2014 - 11:27 AM