Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Time.Elapsed Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Gunz




PostPosted: Sun Jan 02, 2011 9:46 am   Post subject: 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..


Turing:


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
<Answer Here>
Sponsor
Sponsor
Sponsor
sponsor
Dragon20942




PostPosted: Sun Jan 02, 2011 12:10 pm   Post subject: 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




PostPosted: Sun Jan 02, 2011 12:28 pm   Post subject: 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

Turing:

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




PostPosted: Sun Jan 02, 2011 3:09 pm   Post subject: Re: Time.Elapsed Help

Exactly what the problem was Terrance, thanks!!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: