How do I find and remove duplicates in an array?

Get help using Construct 2

Post » Fri Jan 22, 2016 8:56 pm

First of all I have to declare my ever burning hatred for Construct 2 arrays. I have used them before and did more complex things with them then the tutorials thought me but they are a madhouse. Nearly anything I try to do that's more complex than the tutorials seems impossible without bending over backwards. I can't directly do something as simple as finding out the coordinates of a given value in the array without looping, I can't copy information from one array to another properly, never mind manipulating whole rows or columns. Maybe I expected too much of them, thought they'd be more like Excel. So before my head explodes, could someone please let me know if there is a way to find and remove duplicates from an array?
B
7
S
1
Posts: 29
Reputation: 483

Post » Fri Jan 22, 2016 9:22 pm

The simplest way would be to take an empty dictionary, and put all the values of the array in it. That will remove all duplicates. Next clear the array and push all the keys from the array back in.
B
89
S
30
G
95
Posts: 5,157
Reputation: 63,450

Post » Fri Mar 11, 2016 10:21 pm

R0J0hound wrote:The simplest way would be to take an empty dictionary, and put all the values of the array in it. That will remove all duplicates. Next clear the array and push all the keys from the array back in.

Thanks for the idea. The problem was I had to find every pair of identical entries in the array and then decide which one will be deleted by a certain criteria. I was away from my project for a while but now I came back and managed to solve this puzzle in a different way, by using the array in conjunction with object variables, thus avoiding a large number of confusing array loops.
B
7
S
1
Posts: 29
Reputation: 483

Post » Sat Mar 12, 2016 9:20 am

From the other thread -

oosyrag wrote:Conditions
Array - For Each Element

SubEvent Conditions
System - While
System - Compare two values - IndexOf(Array.At.CurX) != LastIndexOf(Array.At.CurX)

Action
Array - Delete LastIndexOf(Self.At.CurX)


This is for a 1d array, but it will still work if you add an additional sub event to check that the second value also matches in both.
Mistakes were made.
B
47
S
23
G
107
Posts: 1,571
Reputation: 60,133

Post » Fri Apr 21, 2017 11:02 pm

How would I make it so that only the values that appear once are deleted?
B
20
S
7
Posts: 195
Reputation: 1,893


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests