Skip to content

Instantly share code, notes, and snippets.

@wolfgangmeyers
Last active August 29, 2015 14:17
Show Gist options
  • Save wolfgangmeyers/68115ab7ddb3936b8841 to your computer and use it in GitHub Desktop.
Save wolfgangmeyers/68115ab7ddb3936b8841 to your computer and use it in GitHub Desktop.
Computercraft script for managing turtle inventory
-- gets a list of all items in a turtle's inventory
function listItems()
local result = {}
for i=1,16 do
local item = turtle.getItemDetail(i)
if item then
local itemName = item["name"]
local itemCount = turtle.getItemCount(i)
result[i] = itemCount .. " " .. itemName
end
end
return result
end
function findItem(itemName)
for i=1,16 do
local item = turtle.getItemDetail(i)
if item then
local name = turtle.getItemDetail(i)["name"]
local j = string.find(name, ":")
if itemName == string.sub(name, j + 1, j + 1 + string.len(itemName)) then
return i
end
end
end
return -1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment