How do I correctly compare two array objects?

0 favourites
  • 10 posts
From the Asset Store
Footsteps SFX Two contains 450 sounds of steps and jumps on different surfaces.
  • I'm trying to handle a "new" vs "old" array situation, and to do this I run(I'm trying to) a complete object to object comparison, currently I'm using a nested "for each X element", for each X on NEW array check with for each X in OLD array.

    But I can't seem to make it work, I was wondering if I'm not using the proper structures to do the run through.

    Here's how I'm building it:

    And this is the array structure data that I'm handling:

  • What is the purpose of your new and old arrays and what/why are you comparing?

    • You can not use 'wait' like that in a 'for each' loop.

    ExistENactual is zero for 10 seconds. Wich will not get a value for 10 seconds.

    • You made a nested loop. Say the 1st array has the values (1,2,3) and the 2nd the values (4,5,6). Because it is nested it evaluates like this :

    1 = 4 ?

    1 = 5 ?

    1 = 6 ?

    2 = 4 ?

    2 = 5 ?

    2 = 6 ?

    3 = 4 ?

    3 = 5 ?

    4 = 6 ?

    You see ? You compare 1 value in one array to all values in the other array.

    You need only one 'for each element'. And the other takes curX from the first one as index.

    For the 'wait', search for "wait in loops'.

    (for future reference ... after the icon of the array in the condition, you see a tinny line, drag that line some to the right, it will reveal/show wich array ... easyer for us to read your events ... ty ty)

  • Hi, thanks for replying.

    Nevermind the "wait" and and text values, this is the cleaner loop:

    Ok then, my intention is to keep updating the "ACTUAL"(old) array with the "NEW" incoming data, because I'll be creating/deleting a related object for every element that needs to be inserted or removed for the ACTUAL array.

    That's why I thought of doing this nested loop thing, and I think what should be happening is the following, just like 99instances highlighted:

    Actually the loops are suposed to solve this array setup:

    NEW = [1,2,3]

    ACTUAL = [1,2]

    //this means that "3" was newly added and needs to be updated into ACTUAL. Like I said, this update involves creating a few objects and some other mumbojumbo.

    Check for missing and push in:

    1 exists in ACTUAL = NO //default to NO(on sub loop start)

    1 = 1 ? YES

    1 = 2 ? ---

    Does 1 exists in ACTUAL? yes, do nothing //it will keep marked to be missing until it actually exists, check 3 below

    2 exists in ACTUAL = NO //by default

    2 = 1? ---

    2 = 2? YES

    Does 2 exists in ACTUAL? yes, do nothing

    3 exists in ACTUAL = NO //default

    3 = 1 ?

    3 = 2 ?

    Does 3 exists in ACTUAL? NO, do do and do.(here I push 3 into actual)

    thanks again.

  • I think that last version worked...., the question now would be how do I push the entire new value, this is the push result:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • NOT, that didn't worked.

    I'm getting this:

  • You can't push the whole row. You push first value, then set the rest explicitly at the new index.

  • Ok now, I've changed (minorlly) the logic and I've located the problem

    The nested array run-through is working, but when checking if "existe = 0" it's not doing anything. (For each NEW when done checking the ACTUALs), I want to do something if it the current NEW element "exists" in ACTUAL.


  • ><<, just noticed something, I was debugging it when existe nevers should stay on 0.

  • Excuse me mu dumbness (again), suppose you wanted to compare each element against each element.

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