# Time math : Any tips?

Discussion and feedback on Construct 2

### » Thu Jan 09, 2014 8:31 pm

Part of my scoring is based on the time it takes to do a level. I want to be able to capture the time they started, the time they ended and then find the difference between the two.

Is this possible in native Construct or are there any libraries or plugins I can use for this purpose?

I could increment a counter every "tick" I guess to keep up with that, but didn't want to add that per tick workload to the game if I didn't need to.

The score requires you to complete a challenge in a single sitting. If you switch apps, you "fault" and no score is recorded though you can come back and finish, you just won't be scored.

Any help would be most appreciated. I've set aside my Construct project for too long and want to get this market (tying up these loose ends) ASAP! :)
B
22
S
4
G
1
Posts: 100
Reputation: 2,150

### » Thu Jan 09, 2014 9:37 pm

Sorry, in a hurry, but here is a timer tutorial:

https://www.scirra.com/tutorials/173/time-counter

and if it didn't format here is a thread I used for my timer in Orbital Bomb-Bounder:

http://www.scirra.com/forum/time-remaining-string-Formatting_topic48212.html
B
255
S
65
G
34
Posts: 907
Reputation: 41,611

### » Thu Jan 09, 2014 9:38 pm

I think having a counter increase every tick isn't really taxing at all, but however, you may be able to do it this way:

Start of Layout
Set a value ("StartTime") to the expression wallclock
End of Layout
Set a value ("EndTime") to wallclock

And then to calculate the time, you simply do Endtime-StartTime.
If not wallclock, there's probably another time expression :P
B
51
S
20
G
10
Posts: 571
Reputation: 9,819

### » Thu Jan 09, 2014 9:47 pm

Best tip I could give is learn what %, or modulo does.
B
178
S
50
G
206
Posts: 8,686
Reputation: 127,715

### » Thu Jan 09, 2014 10:27 pm

var start_time = 0
var pause_time = 0
var pause_total = 0

On Level Start
start_time = time

On Pause
pause_time = time

On Unpause
pause_total = time - pause_time

On End Level
(time - start_time) - pause_time
B
94
S
18
G
9
Posts: 2,457
Reputation: 15,177

### » Fri Jan 10, 2014 2:18 am

Excellent. Thanks!
B
22
S
4
G
1
Posts: 100
Reputation: 2,150

### » Sun Feb 02, 2014 7:47 pm

[QUOTE=newt] Best tip I could give is learn what %, or modulo does.[/QUOTE]

Already know what that does... not sure that answer was much help. Thanks to the others however who pointed me to values to actually get the time.
B
22
S
4
G
1
Posts: 100
Reputation: 2,150

### » Sun Feb 02, 2014 7:59 pm

https://dl.dropboxusercontent.com/u/666516/modulot.capx
B
178
S
50
G
206
Posts: 8,686
Reputation: 127,715

### » Sun Feb 02, 2014 11:08 pm

Sounds easy enough. My suggestion:

1) Set a global variable to 0 at the start of the level
2) On every tick, add dt to the variable

The global variable will contain the number of seconds that have passed since your event 2 became active.

Check out this manual entrynusbaumc2014-02-02 23:09:02
B
9
S
3
Posts: 37
Reputation: 749

### » Mon Feb 03, 2014 7:27 am

When you want it to record the first moment: set value timecheck = wallclocktime

when your done, set the value again: timecheck = wallclocktime - timecheck.

Voila, time difference between begin and end time.
Who dares wins
B
57
S
17
G
21
Posts: 1,880
Reputation: 19,628

Next