Placing a value in an array at the next open spot?

0 favourites
  • 4 posts
From the Asset Store
10 Orchestral Soundtracks / ~2 mins each / 11 audio clips in total
  • I feel stupid for not asking this earlier, but I've set up an entire inventory system, and adding a new item requires like, 16 events for each item slot. It didn't hit me until now, but is there a way for me to pick the next open spot on an array. To be more specific, say an event sets 1,0 to 1, then it triggers again, and instead of picking 1,0 it picks 2,0?

    I really feel stupid for even having to ask this question.

  • If you are able to define "open" as a value in your array, for example 0, you can use the IndexOf expression to find the index of the open slot.

  • Also, instead of searching for an empty slot, you can use Insert/Push/Pop actions to add/remove elements.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can also "use for each element" in arrays. So another approach would be to loop through the array, and as soon as you hit a "free" spot you place the item there and stop the loop, or you could also continue the loop if you're picking up multiple things at once, and stop the loop when all the things has been placed in the inventory.

    Somehing like that could also work.

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