green text is being edited and should not be considered
relevant to the tutorial. for a while, it will make up
the bulk of this section.
black text has been edited to be more accurate with
regards to puppybasic.
........................................................................
timing
1 of 7
an intro to puppybasic
chapter 15: timing
........................................................................
........................................................................
timing
2 of 7
vital to graphics and games, and useful for many other things you'll
want to do, the following are common functions for accessing the
timer inside the computer and its clock functions:
TIMER
(mentioned earlier for use with RANDOMIZE) is a numeric function that
returns the number of seconds that have elapsed since midnight.
you can code a delay using TIMER this way...
... (only joking, it's on the next page.)
........................................................................
........................................................................
timing
3 of 7
delay = .5 'delay in seconds, in this case: half of one second
t = TIMER + delay: DO: LOOP UNTIL TIMER > t or TIMER < t - delay * 1.2
it is also possible to create a short delay using FOR q=1 TO d: NEXT q
where d is a large number, but the faster computers get, the more
useless this method becomes. also it is unreliable in that the delay is
longer on slower machines, and that the delay it creates can't be
determined exactly on any machine but the one you try it on.
........................................................................
........................................................................
timing
4 of 7
SLEEP
makes a program suddenly sit and do absolutely nothing until a key is
pressed, and if used with a number:
SLEEP 5
works the same way, only gives up waiting for a key after that number of
seconds.
........................................................................
........................................................................
timing
5 of 7
if used enough times in a program, (especially in a loop,) the keyboard
buffer will fill, which adds up to annoying clicking noises. you can
clear this buffer using INKEY$, but i think it makes more sense to
substitute q$=INPUT$(1) for SLEEP, or a variation of the timer code
example (throw in an INKEY$ function) in this chapter for SLEEP N, and
i usually only use SLEEP when i'm busy enough doing other things to
avoid typing parenthesis: (example: SLEEP is very useful during
debugging.)
........................................................................
........................................................................
timing
6 of 7
TIME$
has the double use of checking and setting the time.
to check the time, let q$=TIME$ which will set q$ to an 8-byte string
comprised of "hh:mm:ss" with hh being a pair of hour digits, mm being
minutes, and ss being seconds.
to set the time, create a string in the same 8-byte "hh:mm:ss" format
and let TIME$=q$
easy!
........................................................................
........................................................................
timing
7 of 7
DATE$ works like TIME$ and checks and sets the date with the format
month-day-year as "mm-dd-yyyy"
note: if your computer is outside the united states, it's possible that
your OS and thus puppybasic will use a different date display.
-= end of chapter 15 =-
........................................................................
an intro to puppybasic (chapter 15)
this content is public domain.
........................................................................
click here to go back to the contents page
Before You Post, Please Note...
-> Please Note: By Posting, you agree to submit the contents of your post to the Public Domain <- SEE: howto post to this blog
Friday, February 2, 2007
puppybasic intro ch. 15 - timing
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment