Pick X value of array based on "contains value"?

0 favourites
  • 10 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • Is there a way to set an array's CurX value by some sort of "contains value?". I'm trying to check my inventory array to see if the item is already in the inventory, and if so, add to the quantity. If it's not in the inventory, add it to first "unassigned" array slot.

  • I'm not sure what you mean by 'contains value', is it any value or a set of specific ones?

    In case you know what the values are you can do something like this for the check.

    if array.curX = value1 OR array.curX = value2..

    or even have all the value in a 2nd array and run a a for, and check if array1.curX = array2.curX

    By unassigned array slot do you mean the 1st one witha 0 value?

  • You probably want something like this. Pay attention to the itemIndex function. It returns -1 if the item isn't contained in the inventory, otherwise, it returns the index of the item.

  • Magistross - I think this is almost what I'm looking for, but I'm having trouble understanding why this is working and how I can apply it to mine

    It doesn't look like the "itemindex" function is being called at all; is it only being used to store a variable?

  • It is called by the addItem function. It first check if an item exists (index != -1), if so, add to its quantity, if not, add a new entry to the inventory array, and set its quantity to 1.

  • Magistross

    Here's what I'm trying to do slightly based on some of the ideas in yours:

    I know its not, but in my mind, this is what this current event list is doing:

    Checks every X value to determine if ItemName exists. If it does, set the loopindex (which would be the CurX of the array) to a variable to add to the existing item's quantity. If it doesn't exist but finds an "unassigned" value, adds the item to inventory. If neither are true (meaning the item is not currently in the inventory and there is no bag space), do nothing.

    I'm beginning to think loopindex isn't working like I think it is, however.

  • You should be using CurX, not loopindex. loopindex is for the System:For event.

  • I don't think loopindex works with the For each axis of the array object, use array.curX or array.curY instead. I don't think stop loop works either... so maybe you should just use a plain "for loop".

  • I missed the Stop loop action. If you want to use Stop loop just switch to the System:For event with loopindex. Magistoss' example show this (System:For).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • blackhornet & Magistross - beautiful! Using a "for" event loop with loopindex works perfectly. Thanks so much!

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