Array Search and return

Get help using Construct 2

Post » Mon Sep 04, 2017 7:02 am

Hi,
Would someone be willing to provide a simple capx that searches a 3D array for a value and returns the location of the value. I would be REALLY appreciative. Thank you.
B
24
S
10
G
1
Posts: 43
Reputation: 2,288

Post » Mon Sep 04, 2017 1:58 pm

Check out my awesome game Doptrix
B
17
S
9
G
29
Posts: 517
Reputation: 16,833

Post » Tue Sep 05, 2017 5:37 pm

You just have to add a third for loop there, for the Z variable, since it's a 3D array. :)

Also, @jhjconstruct, it would be good to know what do you want to do with these indexes, because they may be returned as variables, as a string, as array elements and even as instance variables of the array you're searching. Depending on what you plan some options are better than others.

Cheers.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
19
S
5
G
2
Posts: 537
Reputation: 3,241

Post » Thu Sep 07, 2017 4:14 am

Good point, @brunopalermo , thanks! For some reason I thought array[x,y] is a 3D array :)
I found a much easier way to do this and it works with arrays of any dimensions:
Image

The only problem is that Stop Loop doesn't work there. But of course there are other ways to stop searching after first match.
Check out my awesome game Doptrix
B
17
S
9
G
29
Posts: 517
Reputation: 16,833

Post » Fri Sep 08, 2017 12:01 pm

Thank you, Bruno and dop, REALLY a big Thanx!
B
24
S
10
G
1
Posts: 43
Reputation: 2,288


Return to How do I....?

Who is online

Users browsing this forum: jbr190 and 34 guests