Populate next empty Inventory Slot

0 favourites
  • 3 posts
From the Asset Store
Template for maintaining an inventory with crafting possibilities. Completely documented in text and video.
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • 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

    <img src="smileys/smiley4.gif" border="0" align="middle" />

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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)