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

[Lua] Stopping turtle.dig() from calling turtle.suck() on success.

Started by sabreman, 10 December 2012 - 09:03 PM
sabreman #1
Posted 10 December 2012 - 10:03 PM
Is this possible?
Cloudy #2
Posted 10 December 2012 - 10:28 PM
No. It doesn't call turtle.suck() internally. If you want that behaviour, call turtle.dig() then turtle.drop()
sabreman #3
Posted 10 December 2012 - 10:32 PM
Hmm… Well perhaps you can propose a better solution if I tell you what I'm trying to accomplish?

The issue is i'm trying to check whether of not it's inventory is almost full (ie: strip mining and it still has room for iron, but started dropping cobble). I was thinking of jsut checking for when it can't pick something up, but since it automatically picks up when it digs, this condition would be meant every single time.
1lann #4
Posted 11 December 2012 - 12:43 AM
Hmm… Well perhaps you can propose a better solution if I tell you what I'm trying to accomplish?

The issue is i'm trying to check whether of not it's inventory is almost full (ie: strip mining and it still has room for iron, but started dropping cobble). I was thinking of jsut checking for when it can't pick something up, but since it automatically picks up when it digs, this condition would be meant every single time.

Well one way you can do it is somehow "save" the inventory data, then make the turtle dig and then check it's inventory again. If the two inventories are identical then the turtle mustn't have been able to automatically pickup the dropped object it dug. To improve efficiency, I would only make the turtle do the check if there is something in all of it's slots.

Example code (not tested)

local oldData = {}
local function hasDroppedItem()
  for i = 1,16 do
	if turtle.getItemCount(i) < 1 then
	  return false
	end
  end
  if not oldData[1] then
	for i = 1, 16 do
	  oldData[i] = turtle.getItemCount(i)
	end
	return false
  else
    local sameNumber = 0
	for i = 1, 16 do
	  if oldData[i] ~= turtle.getItemCount(i) then
		oldData[i] = turtle.getItemCount(i)
	  else
		sameNumber = sameNumber+1
	  end
	end
	if sameNumber >= 16 then
	  return true
	else
	  return false
	end
  end
end
		  
Cloudy #5
Posted 11 December 2012 - 03:31 AM
Yeah, just checking the inventory space is the best way to do it.
sabreman #6
Posted 11 December 2012 - 06:58 AM
Oh cool thank you. I can't believe I didn't think of that (although the fact that i wrote that at 2 am might have something to do with it.)