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

<Request> Inventory help.

Started by lolcakes64, 29 April 2012 - 08:57 AM
lolcakes64 #1
Posted 29 April 2012 - 10:57 AM
I made an inventory using tables, whenever you kill a guy it inserts an item into the table. When you press Tab to go to the inventory screen it will show you what you have in your inventory and the inventory screen has an input system (read()) at the bottom.

How do I make it so that when you type something like "eat (any item)" it will eat the requested item you have in your inventory, if you have it. Because I don't want to manually make ALL the ifs and ends and thens when I plan to have tons of items in the game.
epicowner97 #2
Posted 29 April 2012 - 11:01 AM
Isnt is so that you can make 1 variable for all the items that you can eat?
Advert #3
Posted 29 April 2012 - 11:42 AM
You can use a table:


local items = {
"Bear meat",
"Piano",
"Delicious Creeper Supreme"
}
Then reverse it:

for k, v in pairs(items) do
items[k] = v
end
print(items["Piano"])

You'll probably want to make it a bit more sophisticated, though. For example, this example uses strings to store which items you have – I'd probably want to use a table for those.

You might also want to use a separate table for the reverse lookup, since it'd be easier to clear it.
lolcakes64 #4
Posted 30 April 2012 - 04:02 PM
Not really the answers I wanted but I've fixed it now.
Advert #5
Posted 30 April 2012 - 04:52 PM
Not really the answers I wanted but I've fixed it now.

With that attitude, you probably won't get any help at all.

This forum is for learning, and if you don't want to learn, then this isn't the place for you.