Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Waiting / Creating a delay
#1
I need a solid, reliable method of creating a delay in a Qbasic program. Is there a command that can be used to wait a certain time length in a loop? Thanks!
img]http://b.domaindlx.com/cygh/mycophob3.gif[/img]
Reply
#2
you could use wait but i dont knoe much about that.

or you could do this.
Code:
t = TIMER
DO: LOOP UNTIL TIMER - t >= 2

This stays in the loop to secs.
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#3
Quote:you could use wait but i dont know much about that.
or you could do this.
Code:
t = TIMER
DO: LOOP UNTIL TIMER - t >= 2
This stays in the loop two secs.
TIMER returns the elapsed seconds since midnight. If Whitetiger's "t" is an integer, it won't hold the max 84600 seconds in a 24 hour day. So I suggest you use t! instead.
By the way, this is the most commonly used method of creating a delay of n seconds.
*****
Reply
#4
Quote:
whitetiger0990 Wrote:you could use wait but i dont know much about that.
or you could do this.
Code:
t = TIMER
DO: LOOP UNTIL TIMER - t >= 2
This stays in the loop two secs.
TIMER returns the elapsed seconds since midnight. If Whitetiger's "t" is an integer, it won't hold the max 84600 seconds in a 24 hour day. So I suggest you use t! instead.
By the way, this is the most commonly used method of creating a delay of n seconds.
*****
i never knew that
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#5
Because you never bothered to check the FAQ/WIKI system:

http://faq.qbasicnews.com/?blast=DelaySecs

courtesy of yours truly, and

http://faq.qbasicnews.com/?blast=PreciseTimer

courtesy of Mr. Jofers Antoonski.



*sigh*

That's one of the points behind the system: Got a question? Check if there's something useful in the FAQ before asking.
img]http://usuarios.vtr.net/~disaster/sigs/annoyizer.php[/img]
Reply
#6
eh. oh well
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#7
Quote:Because you never bothered to check the FAQ/WIKI system:

http://faq.qbasicnews.com/?blast=DelaySecs
BEWARE OF MIDNIGHT:
As pointed out in the above mentioned url, the delay logic must allow for the possibility that the timer is just about to roll over and is less than n seconds form doing so (n=2 seconds in this example). If you don't code for this possibility, instead of delaying for 2 seconds, you will delay for almost 24 hours.

The code in the above url looks good, but before I were to use it, I would like to know for sure if the timer goes from 0 to 86399 or from 1 to 86400.

A simple piece of code gets complicated when it must work in a 24 hour environment. As I pointed out in a previous post, a similar rollover condition exists when reading today's date with DATE$.
*****
Reply
#8
Thanks for the coding tip, to everyone who helped. I might find it useful later, but at the moment the code slows it down too much. The fastest speed, except for when t! = 0, is still too slow for my program.

Currrently I am using a simple, newbie-ish way of slowing it down:

FOR a = 0 TO delay
NEXT

This snippet slows down the program, but varies from machine to machine. Perhaps I'll research the WAIT command some more, but it seems like nobody really knows much about that one.

If you happen to know an effective method of using the WAIT command or an alternative way of slowing down, any help would be greatly appreciated. Thanks!
img]http://b.domaindlx.com/cygh/mycophob3.gif[/img]
Reply
#9
Quote:Currrently I am using a simple, newbie-ish way of slowing it down:

FOR a = 0 TO delay
NEXT

This snippet slows down the program, but varies from machine to machine.

Hi mycophobiac,

I, too, often use the cheezy FOR/ NEXT method. I have a couple suggestions for it's use...put delay near the top of the file, so that it's easy to find/adjust...or alternatively, allow the user to adjust it. Also, if you make the delay an integer, it often doesn't slow it enough even if it is maxed out...rather than going to a longer type, try the following:

Code:
DEFINT A-Z
CLS
DO
   p& = 0
   INPUT "Gimme a delay (0 to 100)", delay
   PRINT "Q to start over"
   DO
      LOCATE 3: PRINT p&
      p& = p& + 1
      a$ = INKEY$
    
      FOR x = 0 TO delay: FOR x1 = 0 TO delay: FOR x2 = 0 TO delay: FOR x3 = 1 TO delay: NEXT x3, x2, x1, x

   LOOP UNTIL LCASE$(a$) = "q"
   CLS
  
LOOP

By nesting the for/next loops it is much easier to quickly find an appropriate value. In this example, with 4 nested loops, it is equivalent to doing:
FOR x = 0 TO delay^4: NEXT x

0 is still 0...but 10 = 10,000

Also...by putting the delay in 1 line, it's easy to cut and paste.
Cheers
Reply
#10
Try WAIT &H3DA, 8. It'll last approximately 1/70th of a second on most (if not all) machines, and virtually eliminate flicker if you are doing a graphical program.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)