Computer Science Canada

How can i make a timer for my program?

Author:  AshAmo [ 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

Author:  mirhagk [ 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

Author:  AshAmo [ 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.

Author:  Turing_Gamer [ 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.


: