How to constantly changing a random number
Hi communities!
Recently i am developing a function which will spawn enemy "every a random time". I set a timer in "every" and than use the function Random(min,max) to define the time.
It sounds easy but i found out some problem.
The random number only do once! Say, if it random a number 6, the enemy spawn every 6 second, which is not what i want. I want the random number to be constantly changing. What i want is the enemies will spawn in a constantly changing time.
What did i do wrong in my logic? Any opinions? Thanks for help!
Best Answer
-
tatiang Posts: 11,949
If you use an expression in a Timer behavior, it will only evaluate the expression once. So random(3,9) will choose a value such as 6 and just use that the whole time.
You need to create a custom timer: http://forums.gamesalad.com/discussion/comment/464547/#Comment_464547.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Answers
after the random function in your timer you have to add the minimum and maximum time. So if i wanted an actor spawn every 3-5 seconds, my rule would be
Timer
Every random(3,5) seconds
spawn actor (enemy)
Yes that is exactly what i doing. I have put the numbers in it. And as i said, after it random a number between say (3,9), its 6. The number fixed to be 6 and the spawner constantly spawn enemies every 6 sec. Which i dont want happen like that, I want a constantly changed random number in that timer. And make all enemies spawn in different duration.
this is really really helpful! thanks a lot, save my life
Well as long as the "every" tab was selected, it would choose a random number directly after the last.
@zzzz02, it does not work that way. The timer gets its value at the start and sticks to it for every repetition.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com