
-----------------------------------
Gunz
Sun Jan 02, 2011 9:46 am

Time.Elapsed Help
-----------------------------------
Sorry, I am sort of new to turing and my Time.Elapsed starts counting down as soon as my program runs, not when the user clicks on Level 1.


What is it you are trying to achieve?
I want my Time.Elapsed to starting counting down only when I want it to count down.


What is the problem you are having?
So as soon as my program runs, it counts down from 120 and when I choose level 1 it only has like 100 seconds left because the intro takes about 20  secs to run.
Is there any way I can do this???
Below is my timer..




proc timeDisplay
    var timeLeft : int
    var totalTime : int := 120
    loop
        locate (1, 1)
        timeLeft := totalTime - round (Time.Elapsed / 1000)
        put timeLeft
        if timeLeft = 0 then
            cls
        end if
        exit when timeLeft = 0
    end loop
end timeDisplay
timeDisplay




Please specify what version of Turing you are using


-----------------------------------
Dragon20942
Sun Jan 02, 2011 12:10 pm

RE:Time.Elapsed Help
-----------------------------------
Then use an if statement saying if you select level 1, timeDisplay. Looks like a sequence error to me. Can u post the whole code?

-----------------------------------
TerranceN
Sun Jan 02, 2011 12:28 pm

RE:Time.Elapsed Help
-----------------------------------
No I think it's because Time.Elapsed() finds the time since the program started. You need to compare it to the time the game starts running, so something like this


proc timeDisplay
    var startTime : int := Time.Elapsed()
    var timeLeft : int 
    var totalTime : int := 120 
    loop 
        locate (1, 1) 
        timeLeft := totalTime - (Time.Elapsed() - startTime) div 1000
        put timeLeft 
        if timeLeft = 0 then 
            cls 
        end if 
        exit when timeLeft = 0 
    end loop 
end timeDisplay

Input.Pause
timeDisplay


Note the line where timeLeft is set, I found the difference in time between how long the program has been running and the startTime, then used that value just like you did.

-----------------------------------
Gunz
Sun Jan 02, 2011 3:09 pm

Re: Time.Elapsed Help
-----------------------------------
Exactly what the problem was Terrance, thanks!!
