How to make a random timer?
therobinsonbros@gmail.com
Member Posts: 34
I want to make a time bomb that goes off at any time, and when it go off it's game over. I looked up a video on how to make a timer. So I have an idea on how to get it started, I just don't know how to make it random.
Comments
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
In your bomb actor create a timer behavior. Then, in the expression editor window click on the insert function down arrow and select "random". It should now have random(min,max) in the expression textbox. Replace the min and max with the min and max amount of seconds before you want the bomb to explode.
AppTaco LLC
http://www.apptacostudio.com/
https://www.facebook.com/apptacostudio
Run game over code
Or this way...
Change Attribute: game.bombTimer = random(6,30)
Timer: Every 1 second
Change Attribute: game.bombTimer = game.bombTimer - 1
Rule: If game.bombTimer = 0
Run game over code
Now make a rule below the timer and change it to attribute then use the attribute that you created above. do equals to then any number in the range of the random. then add what ever you want to happen when the bomb blows up. This should work.
-Coyote
This is how my normal code look. This work and count down from 15, but it's not random.
Display Text:
abs(prec(game.my timer,2))
change attribute:
set: game.start time to: game.time
Rule:
if game.my timer >0
Do:
constrain attribute:
constrain: game. my timer to 15-(game.time-game.start time)
Rule:
if game.my timer = 0
destroy this actor
How can I make this code pick a random start time out of 6 to 30 sec, and end at 0.
I think what u need to do is make a integer Name it Bomb Timer to make it easy and keep it at 0.
IN a actor like your background in the scene make a rule that changes the interger to a random number make it look like (6, 30).
Make your Bomb actor and in the actor make a rule and put a timer in the do section of the rule. The rule will be attribute in the box click the E beside it.
In the window that opens click Game then Bomb Timer which is your integer u made a sec ago. click the check mark. Make sure the if Grater than > symbol is selected. And the box should b set to 0 if not set to 0
Then in the do section in that rule where the timer is make it Every 1 second. In the box in the timer type or drag in change attribute. in the change attribute click the E make select Game.BombTimer like before in the next box the important part come in u select the E again and select Game then Bomb Timer-1 Then click the check box.
This will change your integer AKA your Bomb Timer to -1 per secound.
It doesn't end there since you want to make the Bomb blow up at 0 Bomb timer.
Make a new rule in the bomb in this rule put in attribute Game.Bomb Timer = 0
In the do section make the destroy actor and Spawn a Explosion Actor.
Also make another actor just to display the Bomb timer. Make new actor and in the actor drag or type display text. Click the E button again and set it to Game. Bomb Timer. Re-size the font if needed. Might want to make a rule when Bomb timer = 0 destroy the actor so the text goes when bomb blows up.
I just tested this and it works so good luck