How do I correctly compare two array objects?

Get help using Construct 2

Post » Mon Aug 22, 2016 12:00 pm

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

And this is the array structure data that I'm handling:
Image
B
4
Posts: 7
Reputation: 489

Post » Mon Aug 22, 2016 4:28 pm

What is the purpose of your new and old arrays and what/why are you comparing?
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Mon Aug 22, 2016 5:19 pm

- 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)
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue Aug 23, 2016 11:07 am

Hi, thanks for replying.
Nevermind the "wait" and and text values, this is the cleaner loop:
Image

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.
B
4
Posts: 7
Reputation: 489

Post » Tue Aug 23, 2016 11:36 am

I think that last version worked...., the question now would be how do I push the entire new value, this is the push result:
Image
B
4
Posts: 7
Reputation: 489

Post » Tue Aug 23, 2016 11:45 am

NOT, that didn't worked.
I'm getting this:

Image
B
4
Posts: 7
Reputation: 489

Post » Tue Aug 23, 2016 1:41 pm

You can't push the whole row. You push first value, then set the rest explicitly at the new index.
ImageImageImage
B
71
S
21
G
230
Posts: 3,688
Reputation: 128,847

Post » Tue Aug 23, 2016 6:56 pm

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

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.

Greetings.
B
4
Posts: 7
Reputation: 489

Post » Tue Aug 23, 2016 7:08 pm

>><<, just noticed something, I was debugging it when existe nevers should stay on 0.
B
4
Posts: 7
Reputation: 489

Post » Tue Aug 23, 2016 9:32 pm

Excuse me mu dumbness (again), suppose you wanted to compare each element against each element.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, guannstar, marcinkowski, Shenkai the ssj, Yahoo [Bot] and 14 guests