How Do I Check If Variable Holds a Certain Number

0 favourites
  • 8 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I have scoured the forums, but couldn't find an answer. Here is the problem: I have 10 different sprites that are used for push buttons. I need each sprite to have a random number (1-10) assigned to each sprite variable. The problem I am having is that I don't want there to be duplicate numbers spanning the 10 sprites. Is there a way to check each sprite variable and if there is a number that is in another sprite variable it randomizes again until the sprite has a number not being used. The first sprite variable being assigned a random number is not a problem because that is always the starting sprite variable that does not need to be checked, all the following sprite variables need to be checked. This happens until each sprite variable has a number 1-10 without duplicates. I am sure there is a easy answer to this that I am missing. I appreciate any help.

    Thank You In Advance


  • There are different solutions (like helper objects that disappear, instance variables or loops that check if already used)

    But the best one would be an Array. Here you randomize your Array and pull a number from it (see tutorials for Arrays)

  • Thank you blackhornet and fm4fanAT. I really appreciate the help. I have been trying blackhornet's plugin, but can't figure out how to set the random numbers to the variables.

    I am going to give the array tutorial a try as well. Thank you both for the help.


  • The Next expression will pull out the next random number.

  • OK I am still having a problem understanding this. Say I have variable $PushButton1, $PushButton2, $PushButton3, etc. all the way to $PushButton10. Will the Next Expression fill these variables with the random numbers generated without duplicates in order? Just trying to wrap my head around how the expressions and code work in the plugin. Thank you for the info in advance.


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes. You'd be better off using an array, but this will work:

    PushButton1 = BHTSmartRandom.Next

    PushButton2 = BHTSmartRandom.Next

    PushButton3 = BHTSmartRandom.Next


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