Arrays : How do I locate to a specific value

Get help using Construct 2

Post » Wed Aug 21, 2013 7:02 pm

My question is kind of generic.

I am aware that arrays are not datasets so as to locate to a certain entry, however I am working on a 3D array that contains lots of info and I am in need of finding the position of a specific entry (or more) and then get one of dimentions (all fields from that dimention) for further use...

So I was wondering if there was a quicker way to get to the info I need than the one I've currently implemented.

What I currently do.
1. I check if the value (ie.: "name") I am looking for is contained in the array.
2. I loop twice each dimention (Height,Depth)
   and when "name"=Myarray.At(x,Height++,Depth++)
   get the info I need for all x fields for each Height and Depth found to be matching.

As far as I am concerned this works fine and there is no delay, however i keep wondering if there is some smarter way to do it.
B
11
S
4
G
5
Posts: 9
Reputation: 3,780

Post » Wed Aug 21, 2013 8:07 pm

You might want to fiddle with Array.indexOf, it returns the X-index of a given value (or -1 if not found). But the documentation isn't really clear on how it behaves with 3-D arrays.
B
71
S
30
G
25
Posts: 984
Reputation: 19,503

Post » Wed Aug 21, 2013 8:20 pm

Thx but in any case this gives the first instance found and LastIndexof gets the first from reverse (or last...). But if I have 3 values that correspond to "name", I am missing one, this way.
B
11
S
4
G
5
Posts: 9
Reputation: 3,780

Post » Wed Aug 21, 2013 8:32 pm

Oh, so you can have multiple identical entries ? How about a function that return a string with all matching index concatanated with a separator ?
B
71
S
30
G
25
Posts: 984
Reputation: 19,503

Post » Wed Aug 21, 2013 9:21 pm

Now i'm loading results to a secondary temporary array and I'm quite happy with how this works, my only issue that currently I'm looping through the other two dimentions to get this done (just like i would in js probably).

My array is a comprehensive Tech tree for the game I'm making
1 dimention = [Tech Level],[Tech Level Title],[Tech Level subtext]
2 dimention = [Type of Technology],[Type SubText]
3 dimention = [id],[Name of Tech],[Subtype],[Description],[Research Points],.... n=25

So I'm getting all information of dimention 3 where ie [Tech level]<= 4 and [Type of Technology] = Fleet and then load Dropdownlists and a temprary array for the click options. Concatenating [Tech Level subtext],[Type SubText],[Description] provides the full description of the item.

I just didn't like how i made it... I always think there is a better way to do things. :)
B
11
S
4
G
5
Posts: 9
Reputation: 3,780


Return to How do I....?

Who is online

Users browsing this forum: FabianB and 11 guests