How do I find and remove duplicates in an array?

0 favourites
  • 5 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • 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?

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

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

  • From the other thread -

    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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • How would I make it so that only the values that appear once are deleted?

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