How do I scan an array and build a second one?

Get help using Construct 2

Post » Sun Sep 28, 2014 12:24 am

I have an array being filled with data using AJAX and CSV>ARRAY and this works great.

I would like to scan the entire array and build a secondary array that tracks empty entries and their position in the original array.

I am trying to build a For or a While or a For Each loop to do this but I am failing.

I am using len(Array.At(CurrentPosition, 3, 0)) > 0 to look for empty array cells in the 4th column of each part of the For loop but my Construct build is simply not working.

0- XXXX
1- XOOX
2- XXOX
3- OOXX
4- XOXO
5- OXXO
6- OXOX
7- XOOO
8- OOOX
9- OOOO

For each Array.Entry IF Column 3 = X then Push To Back the Current.For into New.Array

This would result in the New.Array of:
0- 0
1- 1
2- 2
3- 3
4- 6
5- 8

Thanks for looking!
B
10
S
4
G
2
Posts: 133
Reputation: 2,667

Post » Sun Sep 28, 2014 4:02 am

Assuming it's a 2d array of text and that an "empty" slot will have an "X" in it.

Array: W=4, H=3, D=1
Array2: W=0, H=1, D=1

For "" from 0 to array.height - 1
Array.at(3, loopindex)) = "X" --> Array2:Push back loopindex on X axis

Edit: fixed a basic error. see capx. sorry if I caused you more confusion. After re-reading the OP It seems you want to check for "X", not empty cell.
You do not have the required permissions to view the files attached to this post.
Last edited by codah on Sun Sep 28, 2014 6:11 am, edited 4 times in total.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Sun Sep 28, 2014 5:26 am

Interesting. That is close to what I've tried and failed but different in a few key ways... Thanks! I'll give this a try.
B
10
S
4
G
2
Posts: 133
Reputation: 2,667

Post » Sun Sep 28, 2014 6:09 am

See update above ^^
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Sun Sep 28, 2014 10:33 am

codah wrote:After re-reading the OP It seems you want to check for "X", not empty cell.


I was using the X and O as an example...

Yes its a 2d array.

The actual array looks like this:

0 text,text,,text
1 text,,,
2 text, text, text, text
3 text,,,
4 text,,,text
5 text,,,text
6 text,text,,text

and I am hoping to scan the array and build a second array that tells me which entries have text in the last column. The resulting array would look like this:

0 0
1 2
2 4
3 5
4 6

I hope this makes sense... I think I can figure it out from what you've posted though...

Thanks!!
B
10
S
4
G
2
Posts: 133
Reputation: 2,667

Post » Sun Sep 28, 2014 11:48 am

ok then try this
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Sep 29, 2014 6:29 pm

This is much more complicated than I need but definitely covers almost every possibility I would ever need.

I think that because all I need is the Array.At position for any empty cell I won't need to do the Log In Browser... but wow that's a cool trick. I didn't know you could do that.

Thanks for all the help! If I can't figure out the rest from here I should just give up and learn to drive a big truck :)
B
10
S
4
G
2
Posts: 133
Reputation: 2,667

Post » Mon Sep 29, 2014 10:44 pm

goblynn93 wrote: I won't need to do the Log In Browser... but wow that's a cool trick. I didn't know you could do that.)


um.. that was just for debugging....

Here is the relevant bit. Not sure how that's complicated.. :?
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Oct 01, 2014 7:01 pm

By complicated I meant the Browser log stuff was doing a lot more than I needed.

I have built a similar loop but for some reason it runs forever... It should run 11 times and stop but it just keeps going and going forever if I let it go...

***
AHA! I needed a trigger... or else it just keeps looping 0-10 0-10 over and over...

Making progress :D thanks for the help!
You do not have the required permissions to view the files attached to this post.
B
10
S
4
G
2
Posts: 133
Reputation: 2,667

Post » Wed Oct 01, 2014 10:52 pm

goblynn93 wrote:By complicated I meant the Browser log stuff was doing a lot more than I needed.

I have built a similar loop but for some reason it runs forever... It should run 11 times and stop but it just keeps going and going forever if I let it go...

***
AHA! I needed a trigger... or else it just keeps looping 0-10 0-10 over and over...

Making progress :D thanks for the help!


Yep I had it under On Start of Layout but you could put it in a Function, etc. Anyway well done making progress :) I've been dealing with arrays for 32 years but C2 still trips me up with them all the time :|
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596


Return to How do I....?

Who is online

Users browsing this forum: Laura_D and 25 guests