How to remove duplicate values from an array in Construct 2

0 favourites
  • 5 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • Hi all,

    I'm editing a game in Construct 2 and I want it to select 8 different random letters (3 vowels and 5 consonants). The problem in the script is that it sometimes repeats letters from the array. Does anyone know how can I force the script not to repeat letters in the random selection?

    Here is the code:

    Thanks in advance,

    Bernardo

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can delete elements from the array.

    Pick random letter, then remove it from the array.

  • Thanks for your answer, dop2000.

    Unfortunately, my knowledge of construct is still poor.

    I've figured out a solution: to force portions of the alphabet in each value (the first letter is "a", second is "e" or "i", third is "o" or "u", and the same with the consonants, forcing blocks of 3 letters for each value). It's a bit of a drab idea, but it works.

    The idea of removing letters from the array seems interesting, but I don't know how to do that. :S

  • Oh, wait, you want to add 8 random letters to the array? (I thought you are picking letters from the array)

    You can first add the entire alphabet to the array and then delete 18 random elements:

    Array Load from JSON "{""c2array"":true,""size"":[26,1,1],""data"":[[[""a""]],[[""b""]],[[""c""]], .... }"

    System Repeat 18 times -> Array Delete index (int(random(array.width)))

  • Many thanks, dop2000!

    I'll try that later

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