Page 1 of 1

Inventory Management help [SOLVED]

Posted: Thu Jul 21, 2016 11:48 pm
by ThiefOfPringles
Heyyyy,

So my goal of this little project is to have some sort of inventory management going. What im wanting it to do is, when it adds the new item, it pushes the first one back and lets the new item take it's slot. but instead of that happening, it just replaces the item.

Re: Inventory Management help

Posted: Fri Jul 22, 2016 4:39 pm
by Plu
You seem to have made a two-dimensional inventory, where each entry in the inventory can, itself, contain multiple items. I don't think that's intentional, and it's probably causing your issue.

Your inventory starts out like this:

Code: Select all

{ {}, {}, {}, {}, {} } -- 5 empty entries
Then, when you add your first entry, you insert it in inventory[1], which means your inventory looks like this:

Code: Select all

{ { 1 = <item#1> },{}, {}, {}, {} } -- 1 item 
And then, when you add another entry, you again insert it in inventory[1], which means now it looks like this:

Code: Select all

{ { 1 = <item#2>, 2 = <item#1> }, {}, {}, {}, {} } -- 2 items
I'm pretty sure that's not what you thought you were doing :)
It really helps to try and use a debugger to see what the contents of a table really look like.

Re: Inventory Management help

Posted: Fri Jul 22, 2016 4:53 pm
by Xugro
Plu explained your problem. I modified your code to show you a way to do it.

Re: Inventory Management help

Posted: Sat Jul 23, 2016 3:40 am
by ThiefOfPringles
Thank you so much! I'll be sure to remember the advice about the debugger