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.
Inventory Management help [SOLVED]
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 17
- Joined: Fri Feb 26, 2016 1:42 pm
Inventory Management help [SOLVED]
- Attachments
-
- inventoryTest.love
- (9.09 KiB) Downloaded 102 times
Last edited by ThiefOfPringles on Sun Jul 24, 2016 12:28 am, edited 1 time in total.
Re: Inventory Management help
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:
Then, when you add your first entry, you insert it in inventory[1], which means your inventory looks like this:
And then, when you add another entry, you again insert it in inventory[1], which means now it looks like this:
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.
Your inventory starts out like this:
Code: Select all
{ {}, {}, {}, {}, {} } -- 5 empty entries
Code: Select all
{ { 1 = <item#1> },{}, {}, {}, {} } -- 1 item
Code: Select all
{ { 1 = <item#2>, 2 = <item#1> }, {}, {}, {}, {} } -- 2 items
It really helps to try and use a debugger to see what the contents of a table really look like.
Re: Inventory Management help
Plu explained your problem. I modified your code to show you a way to do it.
- Attachments
-
- inventoryTest_working.love
- (9.19 KiB) Downloaded 88 times
-
- Prole
- Posts: 17
- Joined: Fri Feb 26, 2016 1:42 pm
Re: Inventory Management help
Thank you so much! I'll be sure to remember the advice about the debugger
Who is online
Users browsing this forum: No registered users and 4 guests