Qbasicnews.com

Full Version: how to time things
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
how do i time things with a timer or something like animations, rotations, enemys movements and stuff?
TIMER
TIMER give you the number of seconds that have passed since midnight. You can use it to time just about anything. It's only limitation is that it changes only about 18 times a second, so it won't work if you want to do something at a higher frequency than that.

Example:
Code:
INPUT "How many seconds do you want to wait?", seconds

timeToWaitFor! = TIMER + seconds
DO: LOOP UNTIL TIMER >= timeToWaitFor!
Many qb game programming libraries, such as directQB, UGL, and Future.Library come with timing routines that are better suited for animation etc. I'd suggest you check one of them out (I'd recommend DirectQB only because it's the best documented) and read it's manual and learn how to use it's timing routines.
Best documented, pfffft.
Well atleast its best among the documented libraries =P
If you're using a library solely for its timing routines, you might as well use Seav's routine that changes the timer's refresh rate:

Code:
FUNCTION CLOCK&

' Get the number of timer ticks at
' 0000:046C
DEF SEG = 0
Ticks& = PEEK(&H46C)
Ticks& = Ticks& + PEEK(&H46D) * 256&
Ticks& = Ticks& + PEEK(&H46E) * 65536&
DEF SEG

' Latch the counter and obtain the PIT
' countdown status.
OUT &H43, &H4
LSB = INP(&H40)
HSB = 255 - INP(&H40)

' Compute the CLOCK& value
CLOCK& = Ticks& * 256& + HSB

END FUNCTION

to test it:
CLS
DO
TimerVal! = TIMER
ClockVal! = CLOCK / 4660.859#

LOCATE 1
PRINT USING "CLOCK: #####.###"; ClockVal!
PRINT USING "TIMER: #####.###"; TimerVal!
LOOP UNTIL LEN(INKEY$)