# Conditionally Sorting 3D Arrays

Get help using Construct 2

### » Thu Sep 12, 2013 4:53 am

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:

[code]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[/code]
to:
[code]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[/code]TL222013-09-12 04:54:16
B
108
S
37
G
9
Posts: 319
Reputation: 12,359

### » Thu Sep 12, 2013 5:26 am

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.
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,289

### » Mon Sep 16, 2013 4:36 pm

Took a little finagling but it works pretty great now. Boy do I feel sheepish. Thanks Tulamide!
B
108
S
37
G
9
Posts: 319
Reputation: 12,359