GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to make a random timer?

therobinsonbros@gmail.com[email protected] Posts: 34Member
edited October 2013 in Working with GS (PC)
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

  • jamie_cjamie_c ImagineLabs.rocks Posts: 5,541Member
    I don't know what timer tutorial you saw but you need to use the Random function in the expression editor to create random numbers.
  • AppTacoAppTaco Posts: 125Member
    Hello,
    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.
  • this is the tutorial I use to start the timer... I just want this type of code to be random.
  • It still didn't come out the way I wanted. I want to have a set time of 30sec, and the lowest to be 6 sec. I'm want the game to pick a random number from 6 to 30 sec each time you play it, and when the time reach 0 game over.
  • KevinCrossKevinCross London, UKPosts: 1,893Member
    edited October 2013
    Timer: After random(6,30)
    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
  • CoyotepeltCoyotepelt Posts: 3Member
    In the bomb make a timer. do every .5 secs... then make an attribute for a number (not real). put change attribute change the attribute that was just created. Hit the e on change to. Then hit the button next to the arrow down then click random or something like that. change the max to 5 or something and the min to 1 or something.
    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
  • therobinsonbros@gmail.com[email protected] Posts: 34Member
    edited October 2013
    I'm still lost here.. now sometime my number start to count up... or start to count down really slowly.

    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 hope I'm not being a pain... I'm new to this. lol
  • grimmagelolgrimmagelol Posts: 18Member
    Have u tried what KevinCross said? First do u need to change start time to game time?

    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 :)
Sign In or Register to comment.