
-----------------------------------
tianxiao
Tue Jan 13, 2009 12:23 pm

How do you set up a timer in turing? I wanna run a game and see how long a person takes to complete it.
-----------------------------------
How do you set up a timer in turing? I wanna run a game and see how long a person takes to complete it. So starting from the time the program starts running till the game ends. How do i make that timer?

-----------------------------------
copthesaint
Tue Jan 13, 2009 12:32 pm

RE:How do you set up a timer in turing? I wanna run a game and see how long a person takes to complete it.
-----------------------------------
First make 2 vars the timer for when to start and 1 for finish

var timerI,timerF : int

timerI := Time.Sec 
loop
timerF :=  Time.Sec 
put (timerF-timerI)
if timerI + 10 < timerF then
quit
end if
View.Update
cls
end loop

-----------------------------------
Zren
Tue Jan 13, 2009 12:44 pm

Re: How do you set up a timer in turing? I wanna run a game and see how long a person takes to complete it.
-----------------------------------
Edit: Monkeys, copthesaint types fast, :/

Look up the Time. module for more things like Days and Years...

Time.Sec returns the seconds it's been since...uh jan __ 1970 at midnight.

var t := Time.Sec

This isn't really usefull by itself...BUT if we took to times and compared them (TimeB -TimeA) then we'd have the difference in time or &#916;t. For our use TimeA would be when the game starts, and TimeB would be when the game ends.

-----------------------------------
The_Bean
Tue Jan 13, 2009 1:22 pm

Re: How do you set up a timer in turing? I wanna run a game and see how long a person takes to complete it.
-----------------------------------
Or you could simply use Time.Elapsed which returns the number of milliseconds since the program started.

-----------------------------------
copthesaint
Tue Jan 13, 2009 3:11 pm

RE:How do you set up a timer in turing? I wanna run a game and see how long a person takes to complete it.
-----------------------------------
The bean if you use that then the program will have different time limits each game esspecially is you have a menu
the way I did is good for effects and timers.

-----------------------------------
The_Bean
Tue Jan 13, 2009 5:41 pm

Re: How do you set up a timer in turing? I wanna run a game and see how long a person takes to complete it.
-----------------------------------
Actually no it won't.
Your getting that start time saving it as a variable and subtracting it from the current time.  Do the exact same thing with Time.Elapsed and you will get the exact same amount of time.  

The major difference is that Time.Elapsed deals in milliseconds, so you have more accuracy.

A program that draws a black box every other 1.25 seconds.

View.Set ("offscreenonly")
var timeStart : int
timeStart := Time.Elapsed
loop
    cls
    if ((timeStart - Time.Elapsed) div 1250) rem 2 = 0 then
        Draw.FillBox (0, 0, maxx, maxy, 7)
    end if
    View.Update
end loop

Time.Sec is an integer so your limited to 1,2,3... seconds so you can't get 1.25 like you can with Time.Elapsed
