How can I randomly choose two precise numbers?
Simple Gamer Arts
Member, PRO Posts: 305
I want to randomly choose just these two numbers: -100 and 100 (not -99 or 56). Any ideas?
Comments
Create two integer attributes called game.whichOne and game.randomNumber
[repeat with a loop, Timer, rule condition, etc.]
Change attribute game.whichOne to 0
Change attribute game.whichOne to random(1,2)
When attribute game.whichOne = 1
Change attribute game.randomNumber to -100
When attribute game.whichOne = 2
Change attribute game.randomNumber to 100
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thanks a lot @tatiang that works fine!
Or a simpler way:
Change attribute game.randomNumber to (random(0,1) * 2 - 1) * 100
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
This was genius, thanks!!! @tatiang
You're welcome!
Wish I could take credit. I Googled Lua random negative one or one since GameSalad is build in Lua. The first result was this:
https://forums.coronalabs.com/topic/35410-tip-randomly-return-1-or-1/
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User