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

turtle.drop() always drops an entire stack (instead of the set amount)

Started by MistrF8, 23 January 2016 - 03:23 AM
MistrF8 #1
Posted 23 January 2016 - 04:23 AM
Context: I've been writing up a program for a turtle to convert stone into cobblestone, in order to save myself the trouble of course. The problem is, when I use "turtle.dropDown(63)" in my code, it drops the entire stack of cobblestone, every single time.

I know I can alter the code in this program so it can get away with dropping entire stacks, but if possible please could someone tell me a quick way to program my turtle to only drop the amount of items that I tell it to, or if someone could please direct me to a place which addresses and has an solution to this issue (because so far I haven't been able to find such a place).

That being said, here is the code:

local err = 0 -- err is short for "error count"
---------
function errd()
err = err + 1
end -- errd is short for "error detected", I put if statements in the code involving this so it will add to the error count if the program detects anything unusual.
---------
function doIstop()
if err > 0 then
	print("Error detected, stopping...")
	return
end
end -- this program is to stop functions from running if there is an error/s detected.
--------------------------------------
function giveNtake()

print("Dropping Cobblestone...")
turtle.select(2)
turtle.dropDown(63) -- drops 63 C.Stone
-- the turtle seems to drop the
-- entire thing instead of the 63 I set it at! why!?!

if turtle.dropDown() == false then
	errd()
end

print("Aquiring more Stone...")
turtle.select(1)
turtle.suckUp(63) -- gets 63 Stone
turtle.getItemCount(1)
	if turtle.getItemCount() ~= 64 then
	   errd()
	end
print("Back to work.")

end
--------------------------------------
function digNplace()
print("Commencing 'Digging and Placing'")
turtle.select(1) -- location of stone

turtle.detect()
if turtle.detect() == false then
	   for dig = 0, 62 do
		  turtle.place()
		  turtle.dig()
	   end
else
	errd()
end
end
--------------------------------------
-- This is just where I test each function
giveNtake()
doIstop()
--digNplace()
--doIstop()
--giveNtake()
--doIstop()
While I'm complaining about this issue, I might just put something about it in the suggestions area.
Bomb Bloke #2
Posted 23 January 2016 - 04:55 AM
turtle.dropDown(63) works as expected for me, but I'm on CC 1.7whatever.

What happens if you do this?:

if turtle.getItemCount() > 1 then turtle.dropDown(turtle.getItemCount() - 1) end
MistrF8 #3
Posted 23 January 2016 - 08:23 AM
It appears the code you gave me does leave one item in the turtle as I was originally trying to do.

Thank you again Bomb Bloke! :)/>
HPWebcamAble #4
Posted 23 January 2016 - 05:19 PM

function giveNtake()

print("Dropping Cobblestone...")
turtle.select(2)
turtle.dropDown(63) -- drops 63 C.Stone
-- the turtle seems to drop the
-- entire thing instead of the 63 I set it at! why!?!

if turtle.dropDown() == false then
	errd()
end

Heh, think I've found the problem.


turtle.dropDown(63)
Correctly drops 63 items.

But the next line is

if turtle.dropDown() == false then
Which drops that last item. If you wanted to know whether or not the first turtle.drop worked, you'd need to move it into the if-statement, or store the result:


if not turtle.dropDown(63) then --# Same as 'if <thing> == false then'

local result = turtle.dropDown(63)

if not result then