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

0 favourites
  • 10 posts
From the Asset Store
This is a Dungeon Master tool & the 1st of 12 Combat Engines from the Building Combat Engines for Browser Games workshop
  • 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!

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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • See update above ^^

  • 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!!

  • ok then try this

  • 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

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

  • 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 thanks for the help!

  • 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 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)