local function addItemToInventory(inventory,item,amount)
if (inventory[item] ~= nil) then --there are items like this in the inventory already
inventory[item] = inventory[item] + amount --so we add the amount to the ones already there
else --there is no item like this in the inventory
inventory[item] = amount --so the new amount of that item is the one we're adding
end
end
local function removeItemFromInventory(inventory,item,amount)
if (inventory[item] == nil) then return end --there are no such items in the inventory, we do nothing
if (inventory[item] <= amount) then --we're removing more of such items than there are in the inventory
inventory[item] = nil --so we will have no items like it afterwards
else --there is more of such items than we are removing
inventory[item] = inventory[item] - amount --so we subtract the amount we're removing
end
end
local function printItemsInInventory(inventory)
for item,amount in pairs(inventory) do --we're traversing the table, table keys are items, table values are amounts of items
if (type(item)=="table") then --complicated items are represented by a table
print(item.name or "Unknown",amount) --if item has a name we use that, otherwise we use "Unknown" for printing
else --it's a simple item represented by a string
print(item,amount) --we print the item and how much there is of it
end
end
end
local myInventory = {} --our new inventory is a simple table
local myItem = "hammer" --simple item will be a string
local myUniqueItem = {name="superhammer",bonus=5} --special item will be a table with anything we like in it
addItemToInventory(myInventory,myItem,10) --we add 10 hammers to inventory
addItemToInventory(myInventory,myUniqueItem,1) --we add 1 superhammer to inventory
removeItemFromInventory(myInventory,myItem,4) --we remove 4 hammers from inventory
printItemsInInventory(myInventory) --we print contents of the inventory
Thank you so much for that. I truly mean it. However it doesn't seem to work, even when I copy and paste it into the main.lua. I'm such a d*ck at times. That's why I need Love
If I seem aggressive, It's because of my head. Not me. Please do the best you can to deal with it, it's not my fault I'm the way I am.
jjmafiae wrote:you can't just copy and use a code you don't understand go out and learn some lua and then write a code yourself thats how you program for real!
I said EVEN when I copied and pasted it. I tried typing it in first. Read first, Judge later.
If I seem aggressive, It's because of my head. Not me. Please do the best you can to deal with it, it's not my fault I'm the way I am.
jjmafiae wrote:you can't just copy and use a code you don't understand go out and learn some lua and then write a code yourself thats how you program for real!
I said EVEN when I copied and pasted it. I tried typing it in first. Read first, Judge later.
Calm down everybody. The inventory code will print into the console, make sure you have that enabled to see what the code prints.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette! personal page and a raycaster
jjmafiae wrote:you can't just copy and use a code you don't understand go out and learn some lua and then write a code yourself thats how you program for real!
I said EVEN when I copied and pasted it. I tried typing it in first. Read first, Judge later.
Calm down everybody. The inventory code will print into the console, make sure you have that enabled to see what the code prints.
I have, but it just won't say anything. Where exactly do I load it? (and I hope to make an inventory with pictures, not words)
jjmafiae wrote:but if it was a code you made yourself you would know how to fix it, you can't ask for help in all your game modules, im just saying!
I understand what your saying, it's just that I feel you've been slightly (mean?) towards me, but I fully understand what you meant.
If I seem aggressive, It's because of my head. Not me. Please do the best you can to deal with it, it's not my fault I'm the way I am.
Pigeon wrote:I have, but it just won't say anything. Where exactly do I load it? (and I hope to make an inventory with pictures, not words)
Learn what every line of the code does and why it's there. Try drawing a few pictures in a grid on your own and work from there. It will only get harder if you don't understand the basics.
I won't code entire game features for you. What I did provide you with is an example to get you started.
Pigeon wrote:I understand what your saying, it's just that I feel you've been slightly (mean?) towards me, but I fully understand what you meant.
Here's the deal, you openly said "fuck off" to me yet you yourself don't like it when there is even a slight hint of something mean being said to you. Do you see me making a deal out of it? Don't take everything so seriously and personally. Stop looking for things to be insulted over.
We're trying to help you with your problem. Saying sorry repeatedly does not matter in the slightest if you're just going to start arguing with someone the next post you make.
Pigeon wrote:I have, but it just won't say anything. Where exactly do I load it? (and I hope to make an inventory with pictures, not words)
Learn what every line of the code does and why it's there. Try drawing a few pictures in a grid on your own and work from there. It will only get harder if you don't understand the basics.
I won't code entire game features for you. What I did provide you with is an example to get you started.
Pigeon wrote:I understand what your saying, it's just that I feel you've been slightly (mean?) towards me, but I fully understand what you meant.
Here's the deal, you openly said "fuck off" to me yet you yourself don't like it when there is even a slight hint of something mean being said to you. Do you see me making a deal out of it? Don't take everything so seriously and personally. Stop looking for things to be insulted over.
We're trying to help you with your problem. Saying sorry repeatedly does not matter in the slightest if you're just going to start arguing with someone the next post you make.
I can't help the issues I have with my head. That's why when you said 'it might be all in your head' it really hurt me basically, because I have a severe anger disorder. So yeah. I am sorry, but I might not be in the next post, then I will be in the next. It is in my head, but I can't help it. Just don't openly abuse people anymore. It is probably just me who gives two shits. Now I'm sorry but I don't understand the code, because it has yet to have worked.
If I seem aggressive, It's because of my head. Not me. Please do the best you can to deal with it, it's not my fault I'm the way I am.