Populate next empty Inventory Slot

Get help using Construct 2

Post » Fri Nov 22, 2013 4:16 pm

Hi,

I am practicing arrays. I understand the concept of a spreadsheet and cells. The problem I'm having is picking the inventory slot to populate on the inventory screen without assigning a specific slot to each item. I would like the computer to pick the first empty slot.   I tried to read the inventory capx tutorial, but they are more focused on how an array works than on how one would use an array in game.

dropbox.com/s/1ptx6m1b4batzpy/arraypractice.capx

The first action for the item was to compare the array and make sure the item inventory was > or = to 1 so that it would not populate a slot if there was 0 in the array.

The second condition is where I'm having problems. The action for the condition (spawn item at inventory.x and inventory.y) is working.

I tried to set the inventory slot to have a boolean value of filled/ not filled and then have the system action be pick slot by comparison, then toggling the boolean.   Item 2 ended up spawning over item one in the same inventory slot.

I tried to set the instance variable on the inventory slot to a number, then use system-> pick by evaluate, but again, item 2 spawned over item 1.


I tried making the boolean instance a condition instead of having the system check, but that ends up populating all of the empty slots and spawning a large number of items.

I was able to get both items to display properly by setting the system pick to the slot IID, but I would like the system to pick the next empty slot, not the same slot each time.

Any suggestions, or is there an example capx I can see the structure for populating slots on?

Thank you magentamajors2013-11-22 17:06:17
B
9
S
1
Posts: 18
Reputation: 526

Post » Fri Nov 22, 2013 4:31 pm

Tip: You can post URLs as plain text. Makes the no URLs limitation kinda pointless, really.

For filling the first 0 slot of an array, try this (pseudocode)

For loop from 0 to array size - 1:
    If array[loop] = 0:
        Array[loop] = new item
        End loop
B
9
S
1
Posts: 98
Reputation: 853

Post » Fri Nov 22, 2013 5:31 pm

Ah, thank you, I edited the original message to include a dropbox link.


Thank you for your quick response - This has very quickly become frustrating and I already "Rage quit" a few times, so your support is much appreciated.

I fixed the problem - I ended up using

Array at whatever > or = 1
Subevent System -> pick all inventory slots
           Subevent System --> pick by evaluate inventory slot variable
                    System -> trigger once


dropbox.com/s/1ptx6m1b4batzpy/arraypractice.capxmagentamajors2013-11-23 00:14:37
B
9
S
1
Posts: 18
Reputation: 526


Return to How do I....?

Who is online

Users browsing this forum: lukewasthefish, marc254, Mayfly and 14 guests