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

Username:   Password: 
 RegisterRegister   
 How can i make a timer for my program?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
AshAmo




PostPosted: Tue Jan 12, 2010 12:59 pm   Post subject: How can i make a timer for my program?

I am doing a program for school. I making it sort of like the game crazy cars. You need to pass the cars in a certan amount of time.
The only code I can't find anywhere, is how to make a timer. After each car you pass on my game, a count goes up. I'd like the timer to be 30 seconds and after the time is up, if the person hasn't passed enough cars, then they lose.
I would put my program code, but you need my pictures for it to work and I can't upload my file from school.
I really hope someone could please help. Smile
Sponsor
Sponsor
Sponsor
sponsor
mirhagk




PostPosted: Tue Jan 12, 2010 1:29 pm   Post subject: RE:How can i make a timer for my program?

Time.Elapsed will give you the amount of time the program has been running for. so if you have a variable to store the time when the timer started, then you check to see if 30 seconds has passed. (btw it returns it in milliseconds which are 1000th of a second). for example:
Turing:

var timestart:int
put "Are you ready to count to 3!! [press any key to start]"
Input.Pause
timestart:=Time.Elapsed
loop
exit when Time.Elapsed-timestart>3000
end loop
put "3 seconds is up!"


hope that helps you
AshAmo




PostPosted: Thu Jan 14, 2010 12:39 pm   Post subject: Re: How can i make a timer for my program?

Thanks. I tried it and i can't figure out where to put it. I put it in a few spots, and it doesn't work, but it works in the spot where i have it, but then the game gets messed up.


game.t
 Description:
this is the code, you'll need to add your own pictures of something for it to work.

Download
 Filename:  game.t
 Filesize:  3.19 KB
 Downloaded:  103 Time(s)

Turing_Gamer




PostPosted: Thu Jan 14, 2010 2:01 pm   Post subject: Re: How can i make a timer for my program?

When the program starts, timestart := Time.Elapsed
Right before you begin the main program, have timestart := timestart for a guarantied time.
Then have your display showing Time.Elapsed - timestart.
Bracket the operation and 'div 1000' to show it in secs if you want.
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: