Timer as score

Get help using Construct 2

Post » Thu Dec 08, 2011 8:15 am

Just finished the beginning tut and wanted to see how I could create a timer that starts when the game launches and will end (when player dies etc)

When I changed it to every tick update timer by 1 it changed 60 per second which I can understand why.

My problem is how do I tell it every 60 ticks to ++ then get that into a "time" format.

I'm guessing I'd have to format it somehow with a / then display the results? like 120 seconds/60 = 2 Minutes? Am I over thinking this?
B
16
S
2
G
5
Posts: 30
Reputation: 3,925

Post » Thu Dec 08, 2011 9:02 am

New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Thu Dec 08, 2011 9:18 am

[code]global variable Timer
System: Every ticks
    -> add dt to Timer
    local variable min
    local variable sec
        -> System: set min to floor(Timer/60)
        -> System: set sec to int(Timer)%60
        -> Text: set Text to right("00"&min,2)&":"&right("00"&sec,2)[/code]

dt is a special word in c2 that return the time spent between two ticks. so after 60 ticks if you run at 60fps, so 1 second later, Timer will equal 1 (what a coincidence!)
also the right(string,length) function return the right part of a string, so the expression will zero fill the number.
% is the modulo operator:
   0%60 = 0
20%60 = 20
60%60 = 0
80%60 = 20
value tends to cycle when you use modulo. (officially a%b gives the remainder of the euclidian division of a by b... unofficially... easy cycling)Yann2011-12-08 09:24:38
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Thu Dec 08, 2011 6:28 pm

Awesome! Thank you both!
B
16
S
2
G
5
Posts: 30
Reputation: 3,925


Return to How do I....?

Who is online

Users browsing this forum: Vallar and 19 guests