Start and Stop a Timer
blinxteam
Member Posts: 8
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
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
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.
Yes, it counts milliseconds by default.
http://www.funkymunkygames.com/Promo/timerx8_demos.gameproj.zip
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.
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
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
i need the timer for m game thanks
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User