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

Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :)
B
17
S
9
G
70
Posts: 1,053
Reputation: 38,169

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
21
S
6
G
3
Posts: 659
Reputation: 3,845

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.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :)
B
17
S
9
G
70
Posts: 1,053
Reputation: 38,169

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: dop2000, Seruza, Yahoo [Bot] and 11 guests