Hundreds of features to explore
Games made in Construct
Your questions answered
Popular & trusted by schools and Universities world-wide
Construct 3 runs in the browser & works offline
Students do not need accounts with us
Our educational partners
Free education resources to use in the classroom
World class complete documentation
Official and community submitted guides
Learn and share with other game developers
Upload and play games from the Construct community
Game development stories & opinions
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)
Develop games in your browser. Powerful, performant & highly capable.
Just stumbled over a capx that could help you
https://www.scirra.com/tutorials/315/ge ... duplicates
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.
Yes. You'd be better off using an array, but this will work:
PushButton1 = BHTSmartRandom.Next
PushButton2 = BHTSmartRandom.Next
PushButton3 = BHTSmartRandom.Next