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

Subtracting on turtles?

Started by Black_Shad0w, 01 January 2013 - 04:15 AM
Black_Shad0w #1
Posted 01 January 2013 - 05:15 AM
I'm probably just being stupid, but i would like my (felling) turtle to move everything from slot 1 to slot 3( or any other), except for two, but i can't find anywhere how i can do that. What i figured is that i needed to do turtle.getItemCount(1) and then subtract 2 from that, but i can't find how I'm supposed to make it subtract…

(just for fun, ill post my code beneath - not that it matters for this question)


while true do
if turtle.compare() == true then
turtle.select(1)
turtle.refuel(1)
end
while turtle.compare() == true do
turtle.dig()
turtle.digUp()
turtle.up()
end
– print("The tree has been cut down")
while turtle.down() == true do
turtle.down()
end
– print("Back to ground level")
turtle.select(2)
turtle.place()
turtle.select(1)
end
GopherAtl #2
Posted 01 January 2013 - 05:16 AM
ehrum. If I understand the question correctly, you would subtract using the minus sign. ex, 1-1==0.
ChunLing #3
Posted 01 January 2013 - 06:38 AM
I'm thinking you might want to look up some basic Lua. What you need to do here is declare a variable, assign it a value, then do some maths on it.

Typically, you'll do declaration and initial assignment in the same line, like:
local stackSize = turtle.getItemCount(1)

Then you do so math on it:
stackSize = stackSize-2

Then you can use stackSize just like a number (which it contains):
turtle.drop(stackSize)
Tsa6 #4
Posted 01 January 2013 - 12:43 PM
Wait, can't you just do
count=turtle.getItemCout(1)-2
turtle.select(1)
turtle.transfer(3, count)