forums

TNT Basic Forums > Programming Q&A
event timer
< Last Thread     Next Thread >
Author
Thread        Post A Reply

06-27-2003 20:58

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Hi,
I want my code to tell me the length of time since an event, in this case the click of a mouse, this is how I've gone about it so far:

int time
wait mouse click
if mouse button then time=timer 'Gets current timer value

int currenttime=timer-time

repeat
print""
print"",currenttime 'Prints time since mouse was clicked
forever

However, the time variable increments with the timer, giving the exact same result each time. Is there any way where I can get the time variable to equal the timer at that moment only?

06-27-2003 22:14

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

int time
wait mouse click

if mouse button then time=timer 'Gets current timer value
int currenttime=timer-time
>> the 2 vars are at 2 consecutive lines, and TNT is maybe fast enough to do
>> these 2 lines within 1 ms.

repeat
print""
print"",currenttime 'Prints time since mouse was clicked
forever

06-27-2003 22:15

Posted by:
CubeFusion

Location:
California, USA

Find more posts by CubeFusion

The code needs to update the currentTime variable in the middle of the loop like this.

INT time,currentTime
WAIT MOUSE CLICK
IF MOUSE BUTTON THEN time=TIMER 'Gets current timer value

REPEAT
currenttime=TIMER-time
PRINT""
PRINT"",currentTime 'Prints time since mouse was clicked
FOREVER

06-29-2003 15:46

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Thanks CudeFusion, the final code now goes:

int time, currenttime
wait mouse click
if mouse button then time=timer 'gets current timer value

repeat 'Continous curser tracking
currenttime=timer-time
currenttime=currenttime/100
print""
print"In 1000ths of a second since mouse was clicked:",currenttime
forever

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.