Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Timer function problem

Author
Message
Tattered brush
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location:
Posted: 4th Mar 2009 13:11
Hi Guys

I've been reading the excellent timer() tutorial on here and have been experimenting with it.


The above code works as expected. Every 2 seconds the program will print hello.
However if I want to add this into a function (see below), the code no longer functions as expected, can anyone tell me why and if there is a solution please?


Also, is it possible in this case to make T a global, I've tried and it seems to break the program.
Any help would be greatly appreciated.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Mar 2009 18:52
Where you have the line 'T=Timer()' - you need to remember that T is a temporary copy of the original variable. When the function completes, that temporary copy is thrown away.

In addition, the variable 'Elapsed' is temporary within the timed function, so it's results are also thrown away when the function ends - not really a problem because you don't need to keep its value around, but you also don't need to reset it to zero in the function after you've used it.



Tattered brush
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location:
Posted: 4th Mar 2009 20:06
Thanks for your quick response. I have tried your example and it works, I can see alot of uses for this timer based script.
How would I go about breaking the loop so the endscreen() function is executed, say after the screen has printed 10 hellos?

Login to post a reply

Server time is: 2024-09-28 02:25:55
Your offset time is: 2024-09-28 02:25:55