How do I clear an array from double entries?

0 favourites
  • 10 posts
From the Asset Store
Basics sprites and tilesets to build a platformer game or prototype
  • hello,

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

    thanx

  • 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" ?

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

  • 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

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

  • thank you guyz... ill try that!

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

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

  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ArcadEd

    mindfaQ

    NIce tip ArcadEd, it helped me to remove the potential problem of possible double entries before it might even appear!

    Thanx!

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