QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: STxAxTIC on March 28, 2022, 07:57:16 am
-
What happens when the unstoppable force of TIMER meets the immovable object of SLEEP?
When there's a Timer at play, SLEEP never fully halts the program - or, it sorta does. It slows the thing down in kindof an interesting way. Not that anybody should ever depend on SLEEP for anything, so it's weird that this question would come up in the first place.... anyway... Thought I'd share.
-
' set at every 100th of a sec doesn't give much time for sleeping.
How many dots can you make in 2 secs? = how many times you press a key in 2 secs.
On Timer(t1
, 2) moo
' <<< every 2 secs
-
I'd recommend DO: SLEEP: LOOP, but I'd never hear the END of it.
Pete
-
Ha, that's what I do and I don't want to hear the end of it.
-
I'd recommend DO: SLEEP: LOOP, but I'd never hear the END of it.
Pete
DO:SLEEP:A$=INKEY$:LOOP UNTIL whatever you need A$ to be
-
DO:SLEEP:A$=INKEY$:LOOP UNTIL whatever you need A$ to be
DO
a$ = INPUT$(1)
LOOP UNTIL a$ = whatever$
Why the need for SLEEP in there?
-
Pete's screwing around and micronoise took him serious.
-
Pete's screwing around and micronoise took him serious.
Pete *NEVER* screws around -- just ask his wife! Celibate for 50 years now...
It's no wonder she likes me better. 😘
-
Why the need for SLEEP in there?
Reduce CPU usage.
-
@micronoise Why do the Do if all you do is sleep? There's the waste!
I'd do it this way:
-
Reduce CPU usage.
You do realize that SLEEP isn't the only command which limits CPU usage, right?
DO
a$ = INPUT$(1) <-- this drops CPU usage to almost nothing as well, while waiting for a single key press
Or, just as simple:
DO
a$ = INKEY$
_LIMIT 30
LOOP UNTIL a$ = whatever$
SLEEP is honestly a problematic way to go about this type of process, as it's basically nothing more than a DO: _DELAY 0.01: LOOP UNTIL _KEYHIT type process, and there's some old versions of QB64 where SLEEP breaks with unwanted out-of-focus keyhits. (Such as SHIFT-TAB which should be OS reserved to switch app focus between programs.)
INPUT$(1) works much better for a hard pause, while _LIMIT or _DELAY is better with INKEY$ or _KEYHIT, if you make use of ON TIMER events.
(At least, in my opinion...)
-
Sleep let's you look at whatever you've done in 1 loop for however long you like, it's a real advantage for debugging as long as you don't have something on a timer.
-
Maybe a matter of habit ;-) Bear with me, I still consider my self as a newbie. a$=input$(1) is probably better.
-
There is also this nice little feature:
TIMER(BLAH) OFF
that you can call before SLEEPing
then
TIMER(BLAH) ON
when you wake up
-
Hey Steve, don't make me go Will Smith on you! I'd have my wife handle it, but she was out late last night. Ouch, what's this hay doing in the bed? :D
Pete