Start and Stop a Timer

blinxteamblinxteam Member Posts: 8
edited February 2012 in Working with GS (Mac)
Hello,
I am trying to create a timer where when you press play the timer starts and when x collides with y, the timer stops. I already have time running but it starts when the app starts running, I want it to start when the actual game starts. I am new to game salad so bear with me.

Thanks

Comments

  • blinxteamblinxteam Member Posts: 8
    Anyone?
  • HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
    Hi @blinxteam

    If you're talking about the game.time you can't adjust it. You can only reference it in rules.

    So you'll have to make a custom timer. You could either use the timer behaviour or reference the game.timer inside some rules.

    Play about with both and you can decide which suits your game better.
  • blinxteamblinxteam Member Posts: 8
    Thanks. For the advice I will surly do that!
  • blinxteamblinxteam Member Posts: 8
    Is it possible to get the timer down to the milliseconds?
  • CloudsClouds Member Posts: 1,599
    "Is it possible to get the timer down to the milliseconds?"

    Yes, it counts milliseconds by default.
  • blinxteamblinxteam Member Posts: 8
    How do you display the milliseconds on the screen?
  • simo103simo103 Member, PRO Posts: 1,331
    @blinxteam .... I think it was Joe from Firemaplegames that made this a long while ago ... to me it is the definitive clock/timer demo file:

    http://www.funkymunkygames.com/Promo/timerx8_demos.gameproj.zip
  • blinxteamblinxteam Member Posts: 8
    @simo103 Thanks so much this helped a lot! I appreciate it.
  • armbreaker15armbreaker15 Member Posts: 1
    seriously, theres no other way to stop the timer, you have to make your own. boy. Adds another day. Oh well it has to get done.
  • ChakkuChakku Member Posts: 1,513
    @blinxteam @armbreaker15

    maybe you can setup a way to cancel the timer. Then before you cancel it, save how many seconds are left. Then resume the timer when u want to, by also having a rule that turns the timer on when u want to. Then have the timer for as many seconds as you saved.

    "When actorx collides actory, change attribute self.timer (or scene.timer, or even game.timer if its on 1 scene) then when you want to stop the timer, pause the scene.timer attribute, and use the way you setup to stop the timer, to stop it. Then when you want to start it again, start it using the way you setup, and when it says how many seconds, use expression editor to select the attribute that you saved earlier when you paused this.

    Not 100% sure if this will work, as I havent tried it myself. But theres no harm in trying. Give it a go.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2012
    I am trying to create a timer where when you press play the timer starts and when x collides with y, the timer stops. I already have time running but it starts when the app starts running, I want it to start when the actual game starts. I am new to game salad so bear with me.

    Thanks
    Create two game attributes, game.StartTime and game.EndTime (both real type attributes).

    On your play button actor, add this rule:
    • When Touch is Pressed --> Change Attribute game.StartTime to game.Time

    On your actor x, add this rule:
    • When actor collides with actor y --> Change Attribute game.EndTime to game.Time.

    On another actor, add this rule:
    • When game.EndTime>0 --> DisplayText game.EndTime-game.StartTime
    Otherwise --> DisplayText game.Time-game.StartTime

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2012
    And here's a demo that's a bit cleaner than the above code (I added precision to limit the number of digits displayed, but take that out and you'll see the full time displayed):

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • you man can you help i have the same problem but windows doesn't support your file
    i need the timer for m game thanks
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @seanDp32@gmail.com Have you tried this? http://gshelper.com/?p=1655

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.