Last active
August 29, 2015 14:17
-
-
Save wolfgangmeyers/68115ab7ddb3936b8841 to your computer and use it in GitHub Desktop.
Computercraft script for managing turtle inventory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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