Jump to content
Sign in to follow this  
StarvinMarvin

How to make a timer?

Recommended Posts

hey guys! need some help here smile_o.gif

i made an obstacle course and ofcause i want to know how fast i do it wink_o.gif so how do i create a timer that starts when i start the course and stops and shows the time when i complete it..

i know its kinda easy stuff... but easy enough to fool my brain wink_o.gif

gettin rusty..

thanks alot!

Share this post


Link to post
Share on other sites

I almost got it to work by myself with this..

since (time) var is the time the mission have been running i reset it by reduceing it with its own value here at the beginning

//

_timer = time -time

#count

?stoptimer : goto "showtime"

///here its waiting for me to finish///

~0.1

goto "count"

#showtime

///Displays the time taken from start of the script untill stoptime = true///

_timer = time

hint format ["Your time: %1 ", _timer]

~8

///here i wanted to just type hint "timer reset" but that didnt work so i had to use hint format///

hint format ["timer reset"]

exit

//

I always get the time when the script is run.. but the second time i run the course i get the time from that run.. added to the previous run.. for ex: first run (8sec) second run (7sec + 8sec)

tried several ways to reset the variable Time but either it gives me "your time = 0" the first or second run, or it still doesnt reset the timer at all.

Since the scripts starts by making TIME = 0 i supposed it should reset.. but somehow it remembers my old time.

im confused.. to much numbers :P someone please help.

Share this post


Link to post
Share on other sites

hello StarvinMarvin smile_o.gif

try this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_start = time

#count

?stoptimer : goto "showtime"

///here its waiting for me to finish///

~0.1

goto "count"

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">#showtime

///Displays the time taken from start of the script untill stoptime = true///

_end = time

hint format ["Your time: %1 ", _end - _start]

~8

hint format ["timer reset"]

exit

no guarantee though whistle.gif

smile_o.gif

Share this post


Link to post
Share on other sites

You could consider changing the waiting part to

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_start = time

@stoptimer

///here its waiting for me to finish///

goto "showtime"

wink_o.gif

Share this post


Link to post
Share on other sites

Use and .sqf and in it:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_time = 0;

stoptime = false;

while {!stoptime} do {

 _time = _time + 0.1;

 sleep 0.1;

};

_time

and use it in the main script over

_timeNeeded = [] execVM "thatScript.sqf"

Attention: the results might differ with very slow framerate (but that issue the other mentioned examples have as well)

Edit: typo in code

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×