How do I setup items to go into inventory in an order

  • so i have an array in which items spawn in my inventory my inventory is like 40 spaces

    i use parameters

    X=array.CurX

    Value= array.CurValue +1

    and when i click to pick items

    it spawns on

    layer= Inventory_window

    X=inventory_slot_0_0.x

    Y=inventory_slot_0_0.x

    but if i drag item out of the box i understand that the value of my array when i pick items it wants to keep progressing is there a simpler way of having it check for slot is open and put item in the next open slot so if i put items in slot 123, then take out item in slot 2 . next time i pick an item it goes go slot 4 rather than slot 2.... thats what i'm trying to achieve any suggestions or setups?

  • Plug whatever is the value in an empty slot in your array (I assume you use 0) into the "indexof" expression of the array object like so:

    array.indexof(emptyvalue)

    This expression will return the index at which the first X axis element matching the criteria is. Or -1 if an empty slot is not found. So in your case you will get the number of the first empty slot, in which you can put an item. Or if the result is -1 you can do some kind of "inventory is full" message.

  • this sounds good but if put in

    array.indexof(emptyvalue)

    wouldn't the items just get set to going into slot 1 even if there is an item there.... seems like i need some setup to check which slots have items and which are free

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • this sounds good but if put in

    array.indexof(emptyvalue)

    wouldn't the items just get set to going into slot 1 even if there is an item there.... seems like i need some setup to check which slots have items and which are free

    How do mark a slot as empty now? If you have not filled your empty array of size(x,y) with anything there should be a "0" in every empty slot. Look for that 0 with array.indexof(0) and you are good to go. You can also mark empty slots differently, if you want to mark some item with the number 0. But then you would need to fill the array with that value on creation and be careful that only runs once when a new game is started and not on layout start or anything (switching layouts would then delete all values from the array). 0 is a safe bet.

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