Creating an "accurate" lap timer and milliseconds.

For questions about using Classic.

Post » Mon Jun 27, 2011 5:59 pm

Hey folks, back again with something I am stumped on. I am trying to create a visible and accurate lap timer and almost instantly ran into an issue of displaying milliseconds at an accurate rate. I noticed that when you use the "every milliseconds" condition that there is a notice that says "milliseconds wait between triggers". I have tried to build a timer from scratch and don't seem to understand how to accurately get the milliseconds to display in real time.

I searched the construct wiki for a solution and noticed there was an "object" called "profiler" and the wiki described it as dealing with high resolution timers but there was no info on how to use this object or it's purpose in detail.

I put together a very quick cap file that shows what I am trying to achieve and I know it is absolutely inaccurate and might even be the hard way of going about building the timer but you can at the least see what I am trying to achieve.
B
2
G
1
Posts: 37
Reputation: 524

Post » Mon Jun 27, 2011 10:29 pm

You can use the System expression "timer.  "timer" gives the number of milliseconds that have passed since the game started.

Save the start time in a variable and then you can find the number of milliseconds elapsed with:
timer - start_time


B
79
S
24
G
53
Posts: 4,732
Reputation: 40,227

Post » Tue Jun 28, 2011 4:38 pm

My concern is how to correctly "display" the milliseconds during the lap process and not so much catching the time when crossing the finish line.

Also retrieving the milliseconds from the system timer it returns in decimal form with multiple digits. I really want to understand how to correctly put the timer together but man I am confused.
B
2
G
1
Posts: 37
Reputation: 524

Post » Tue Jun 28, 2011 7:31 pm

Here is an example:
http://dl.dropbox.com/u/5426011/examples5/mouseRace.cap

Event 8 in particular:
int('total'/60000) & ":" & zeropad(int('total'/1000)%60 ,2) & "." & zeropad('total'%1000, 3)

I changed timer from decimal to an integer with int(timer).
B
79
S
24
G
53
Posts: 4,732
Reputation: 40,227

Post » Wed Jun 29, 2011 6:21 pm

[QUOTE=R0J0hound]
int('total'/60000) & ":" & zeropad(int('total'/1000)%60 ,2) & "." & zeropad('total'%1000, 3)[/QUOTE]

Line 8 was exactly what I was looking to achieve and I truly smiled when I saw how you simplified that down. I made just a few minor adjustments to add an extra zero to the minutes and changed the decimal in front of the milliseconds to a colon.

zeropad(int('totaltime'/60000),2) & ":" & zeropad(int('totaltime'/1000)%60 ,2) & ":" & zeropad('totaltime'%1000, 3)

I was truly going about it the wrong way. Thanks ROJOhound for the detailed example! It helped me to also understand how to use "int" and bracket correctly when using math.nzso2011-06-29 18:22:23
B
2
G
1
Posts: 37
Reputation: 524


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 11 guests