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

Get help using Construct 2

Post » 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

Post » 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.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » 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
42
S
17
G
17
Posts: 2,247
Reputation: 17,461

Post » 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

Post » 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.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » 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
42
S
17
G
17
Posts: 2,247
Reputation: 17,461

Post » 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...
...
B
44
S
23
G
7
Posts: 286
Reputation: 7,985


Return to How do I....?

Who is online

Users browsing this forum: plinkie and 25 guests