Conditionally Sorting 3D Arrays

  • I'm making an RPG game with an unlockable slot based inventory system. At Level 1 there are 8 slots available, at Level 5 there are 16.

    In my GameData array (which controls all the player modified variables for save files) I store the inventory data in the Z axis, specifically (0,3,1-16). (0,3,0) is where I store the player's currency variable.

    Each slot, 1-16, holds an ID number that corresponds with an item from a different array, ItemDB. If the ID is >=0, then the item slot is filled with an item. If the ID is -1, the item slot is empty. If the ID is -2, the item slot is locked and needs an upgrade to be unlocked.

    How do I auto-sort these items in a 3D array for just that small Z-axis segment from ItemID to Empty to Locked? I found some good examples for a 1D array, but nothing for a 3D array. Basically, this:

    0,3,1  : 12
    0,3,2  :  8
    0,3,3  : -1
    0,3,4  :  3
    0,3,5  : -1
    0,3,6  :  3
    0,3,7  :  5
    0,3,8  : -1
    0,3,9  : -2
    0,3,10 : -2
    0,3,11 : -2
    0,3,12 : -2
    0,3,13 : -2
    0,3,14 : -2
    0,3,15 : -2
    0,3,16 : -2

    to:

    0,3,1  :  3
    0,3,2  :  3
    0,3,3  :  5
    0,3,4  :  8
    0,3,5  : 12
    0,3,6  : -1
    0,3,7  : -1
    0,3,8  : -1
    0,3,9  : -2
    0,3,10 : -2
    0,3,11 : -2
    0,3,12 : -2
    0,3,13 : -2
    0,3,14 : -2
    0,3,15 : -2
    0,3,16 : -2
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • the indices for x and y don't change, so just use the examples you found and simply replace everything that refers to a complete array with the values valid for your z-axis.

    For example:

    For each element => replace with a for loop ranging from 1 to 16

    array size => replace by number 16

    arrayat(x) => replace with arrayat (0, 3, x)

    etc.

  • Took a little finagling but it works pretty great now. Boy do I feel sheepish. Thanks Tulamide!

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