Inventory Management help [SOLVED]

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ThiefOfPringles
Prole
Posts: 17
Joined: Fri Feb 26, 2016 1:42 pm

Inventory Management help [SOLVED]

Post 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.
Attachments
inventoryTest.love
(9.09 KiB) Downloaded 95 times
Last edited by ThiefOfPringles on Sun Jul 24, 2016 12:28 am, edited 1 time in total.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Inventory Management help

Post 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.
Xugro
Party member
Posts: 110
Joined: Wed Sep 29, 2010 8:14 pm

Re: Inventory Management help

Post by Xugro »

Plu explained your problem. I modified your code to show you a way to do it.
Attachments
inventoryTest_working.love
(9.19 KiB) Downloaded 82 times
ThiefOfPringles
Prole
Posts: 17
Joined: Fri Feb 26, 2016 1:42 pm

Re: Inventory Management help

Post by ThiefOfPringles »

Thank you so much! I'll be sure to remember the advice about the debugger
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 55 guests