How do I clear an array from double entries?

Get help using Construct 2

Post » Fri Sep 18, 2015 1:17 pm

hello,

i am looking for a way to remove double entries from 2d array... any tips?

thanx
B
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » Fri Sep 18, 2015 2:28 pm

you can use the action "delete" in the array to delete an entire row of values.

I think I don't really understand your problem... What do you mean when you say "double entries" ?
B
8
S
1
Posts: 76
Reputation: 628

Post » Fri Sep 18, 2015 2:36 pm

hi...

lets say i dont know exact number of entries... and i dont know what to look for... but when i use sort is there a way to check if theres 2 entries in the row with same value and to delete second one?
B
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » Fri Sep 18, 2015 3:01 pm

yes.
for example :
local variable : "PreviousValue"
Array : for each X element :
if Array.At(Array.CurX , 1) = PreviousValue :
then Array(Array.CurX , 1) = 0

Here, I check for every value on Y=1 if the previous value was the same, then I assign 0.

If i didn't answer to your problem, can you post a capx? it will help a lot in understanding
B
8
S
1
Posts: 76
Reputation: 628

Post » Fri Sep 18, 2015 4:22 pm

for each element in array:
-- if dictionary has key array.curvalue: mark for deletion
-- else: dictionary add key array.curvalue

then delete the entries. Array loops don't respond well to deleting element while they are running, so deletion should probably come after the loop.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Fri Sep 18, 2015 5:53 pm

thank you guyz... ill try that!
B
26
S
11
G
2
Posts: 669
Reputation: 5,038

Post » Sat Sep 19, 2015 11:33 pm

You can also use the array Contains Value action to check if that value is already anywhere in the array.
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Sun Sep 20, 2015 7:31 am

ArcadEd wrote:You can also use the array Contains Value action to check if that value is already anywhere in the array.

This will always be true, if you check for the current value. To use this you would need the ability to subset an array, but that's not possible.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Sun Sep 20, 2015 5:50 pm

I mean when dumping the data into the array.

At some point you need to put the info into the array, and that point you can check if that value exists. Unless you do need dups at some point :)
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Sat Sep 26, 2015 10:40 am

@ArcadEd
@mindfaQ

NIce tip ArcadEd, it helped me to remove the potential problem of possible double entries before it might even appear!
Thanx!
B
26
S
11
G
2
Posts: 669
Reputation: 5,038


Return to How do I....?

Who is online

Users browsing this forum: David181, dop2000, namaewayukidesu and 14 guests