Problems with array

0 favourites
  • 7 posts
From the Asset Store
For problem solving, puzzles, bubbles, platforms and other adventures.
  • I intend to generate numbers randomly using array without repetition but sometimes I find a duplicate. I attached the script that I use to create aleatory numbers.

    Thanks in advance

  • Maybe use int() instead of round() in round(random(0,arrayFrame.width)).

    Using round() can cause frameArray to equal arrayFrame.width and trying to delete that index will have no effect.

  • Thank you, R0J0hound

    Living and learning (with the best). I made changes and I think that now everything is okay.

    I've just one more doubt: Why when I use:

    System >Set indexArray to int(random(0, arrayNumbers.Width))

    numbers > Set text to arrayNumbers.At(indexArray)

    I only get zeros (0)?

    Only works if I use:

    numbers > Set text to int(random(0, arrayNumbers.Width))

    Edited: PS - R0J0hound

    I got a duplicate number again. So, it's not working. Do you have another suggestion?

  • If that's giving you zeros then the array may still be all zeros. Did you fill numbers into the array? The other way you used just gives a random number so you could get repeated numbers.

  • Hi R0J0hound

    I didn't fill the array. I've stipulated the width only. I need to fill the array with the 99 numbers before (Set value at 0 to "0", Set value at 1 to "1", ..., Set value at 99 to "99")?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • No use a loop. ex:

    +--------------------+
    |Start of layout     | set array size to (100,1,1)
    +--------------------+
       |array: for each x| set array at array.curX to array.curX
       +-----------------+[/code:rz3kjviz]
  • No use a loop. ex:

    +--------------------+
    |Start of layout     | set array size to (100,1,1)
    +--------------------+
       |array: for each x| set array at array.curX to array.curX
       +-----------------+[/code:xj8qa8ks]
    

    Is this the correct way? "set value at array.curX to array.curX"

    Now the event "numbers > Set text to arrayNumbers.At(indexArray)" is working! And now I can delete the array's number correctly.

    Thank you so much, R0J0hound

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