# How do I detect a specific value in an array (it's x,y,z)?

Get help using Construct 2

### » Mon Apr 17, 2017 6:47 pm

So my for example, i have a 1 in my array and everything else is just 0. Now i want to know what event i need to use to detect where that 1 is in my array by it's coordinates.

How do i do that?
B
5
S
1
Posts: 7
Reputation: 341

### » Mon Apr 17, 2017 7:46 pm

For each XYZ
System compare two values array.curvalue=1

You can then get the coordinates with the Array.curX, array.curY, and array.curZ expressions. Save them to a variable, or push the coordinates into another array if you expect to have multiple locations that have the value 1.
B
59
S
29
G
120
Posts: 1,800
Reputation: 68,000

### » Mon Apr 17, 2017 9:49 pm

oosyrag wrote:For each XYZ
System compare two values array.curvalue=1

You can then get the coordinates with the Array.curX, array.curY, and array.curZ expressions. Save them to a variable, or push the coordinates into another array if you expect to have multiple locations that have the value 1.

You would have to go through every point of the multidimensional array every time you wanted to detect that one value, that would take a ton of processing power and would most likely halt your game if your array is substantially big, How do you generate those one values @OP? Isn't there any way to keep them in a one-dimensional array as multidimensional tokens? For example: "4/2/5"
B
43
S
18
G
17
Posts: 2,247
Reputation: 17,556

### » Tue Apr 18, 2017 4:31 am

Whiteclaws wrote:You would have to go through every point of the multidimensional array every time you wanted to detect that one value, that would take a ton of processing power and would most likely halt your game if your array is substantially big, How do you generate those one values @OP? Isn't there any way to keep them in a one-dimensional array as multidimensional tokens? For example: "4/2/5"

Well, I'm trying this 3D space in just 2D space. So every time I'm moving an object the array deletes itself and refreshes with new 1's. That get input from the objects own X,Y (adjusted). First I tried 250x250x250. The game just froze here. Then I try lower numbers until I reached a good non-laggy game. It was only 38x38. But I could just try with initial variables, I guess it would work the same way.
B
5
S
1
Posts: 7
Reputation: 341

### » Tue Apr 18, 2017 4:38 am

Maybe try a different approach? You can add a "z" instance variable (and a "depth" variable) to each object to base calculations off of.

Using an array in this manner doesn't seem very suitable.
B
59
S
29
G
120
Posts: 1,800
Reputation: 68,000

### » Thu Apr 20, 2017 3:15 pm

Yep, your approach is not optimal in this case, deleting and recreating array every tick is basically butchering your fps
B
43
S
18
G
17
Posts: 2,247
Reputation: 17,556

### » Thu Apr 20, 2017 4:23 pm

Sounds like you are trying to use a 3d array to simulate 3d space? Each cube representing a possible position?

It would be better to use a 2d array to store the coordinates of each object instead. Then you can make the 3d space any size you want...
My in work shmup game CYBERSTORM DEVLOG - "That Terminator is out there. It can't be bargained with. It can't be reasoned with. It doesn't feel pity, or remorse, or fear. And it absolutely will not stop, ever, until you are dead"
B
52
S
27
G
7
Posts: 434
Reputation: 8,910