- This wiki is out of date, use the continuation of this wiki instead
Timer
From FenixWiki
(Difference between revisions)
Revision as of 18:39, 27 December 2007 (edit) Sandman (Talk | contribs) m (→Example) ← Previous diff |
Current revision (00:19, 21 January 2008) (edit) (undo) Sandman (Talk | contribs) m (→Example) |
||
(3 intermediate revisions not shown.) | |||
Line 2: | Line 2: | ||
[[category:predefined]] | [[category:predefined]] | ||
[[category:global variables]] | [[category:global variables]] | ||
+ | [[category:time]] | ||
[[Global variables|'''Up to Global Variables''']] | [[Global variables|'''Up to Global Variables''']] | ||
Line 11: | Line 12: | ||
'''INT[9]''' timer | '''INT[9]''' timer | ||
- | '''Timer''' is a [[global variable]], holding ten integers. Each frame a certain value is added to all of them. This value is the time | + | '''Timer''' is a [[global variable]], holding ten integers. Each [[frame]] a certain value is added to all of them. This value is the difference in time between the start of the last frame and the current frame, in 1/100 seconds. |
- | So when all the timers are never altered, their values will be | + | So when all the timers are never altered, their values will be 1234 when the program has been running for about 12.34 seconds. |
== Example == | == Example == | ||
- | Display how long the program has been running: | + | * Display how long the program has been running: |
<pre> | <pre> | ||
Program timers; | Program timers; | ||
- | Private | ||
- | int ft; // Help variable | ||
- | int i; // how long the program has been running in 1/100s | ||
- | float f; // how long the program has been running in 1/100s | ||
Begin | Begin | ||
- | + | write_int(0,0,100,0,&timer[0]); | |
- | write_int | + | |
- | + | ||
- | + | ||
Repeat | Repeat | ||
- | |||
- | // Calculate how long the program has been running in 1/100s without a float | ||
- | ft %= 10; // keep the milliseconds from last time | ||
- | ft += frame_time*1000; // add the last passed time to it in milliseconds | ||
- | i += ft/10; // add it to the integer without the milliseconds | ||
- | |||
- | // Calculate how long the program has been running in 1/100s with a float | ||
- | f+=frame_time*100; | ||
- | |||
frame; | frame; | ||
Until(key(_ESC)) | Until(key(_ESC)) | ||
Line 45: | Line 30: | ||
End | End | ||
</pre> | </pre> | ||
- | Used in example: | + | Used in example: [[write_int]](), [[key]]() |
+ | |||
+ | This can be done more accurately with the use of [[frame_time]]. | ||
- | Let a [[process]] wait for a certain time by calling this function: | + | * Let a [[process]] wait for a certain time by calling this function: |
<pre> | <pre> | ||
Function int wait(int t) | Function int wait(int t) | ||
Line 57: | Line 44: | ||
</pre> | </pre> | ||
- | This can be done without a timer too, as is displayed [[frame_time|here]]. | + | This can be done without a timer too, as is displayed [[frame_time#Example|here]]. |
{{Globals}} | {{Globals}} |
Current revision
[edit] Definition
INT[9] timer
Timer is a global variable, holding ten integers. Each frame a certain value is added to all of them. This value is the difference in time between the start of the last frame and the current frame, in 1/100 seconds.
So when all the timers are never altered, their values will be 1234 when the program has been running for about 12.34 seconds.
[edit] Example
- Display how long the program has been running:
Program timers; Begin write_int(0,0,100,0,&timer[0]); Repeat frame; Until(key(_ESC)) End
Used in example: write_int(), key()
This can be done more accurately with the use of frame_time.
- Let a process wait for a certain time by calling this function:
Function int wait(int t) Begin t += timer[0]; While(timer[0]<t) frame; End return t-timer[0]; End
This can be done without a timer too, as is displayed here.
Global variables | |
• Argc • Argv • Cdinfo • Dump_type • Fading • Fileinfo • Fps • Frame_time • Full_screen • Graph_mode • Mouse • Os_id • Restore_type • Scale_mode • Scroll • Sound_channels • Sound_freq • Sound_mode • Text_flags • Text_z • Timer • |