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

[Lua][Help]

Started by slymon99, 10 December 2012 - 11:45 AM
slymon99 #1
Posted 10 December 2012 - 12:45 PM
I'm trying to create a isInventoryFull function for my turtles (so they can return after mining their tunnels). I can't get one to work. How do I do this?
Kingdaro #2
Posted 10 December 2012 - 01:57 PM

function isInventoryFull()
  for i=1, 16 do
    if turtle.getItemSpace(i) > 0 then
      return false
    end
  end
  return true
end

The function turtle.getItemSpace() returns the amount of items needed to fill a certain slot. The logic of this function is that it goes through all of the slots of the turtle's inventory, and if it finds a slot that needs items to fill it, it stops and returns false, since it's obviously not full if a slot can receive items. Otherwise, if there are no slots that can have items, it returns true.