Author |
Topic: goto [loop] (Read 614 times) |
|
SarmedNafi
Junior Member
member is offline


Posts: 93
|
 |
Re: goto [loop]
« Reply #8 on: Nov 1st, 2015, 3:34pm » |
|
Quote:[loop] calldll #kernel32, "Sleep", 1 as long, r as long scan goto [loop]
|
|
Actually LB TIMER is a good delay element, we don't need to use SLEEP. The only example shipped with LB is "timerexample.bas", in this example TIMER act as a delay element, the next (tick) is done by the loop not by the TIMER. So I said what am I said, we have not to use (for next loop) but we must use GOTO [LOOP] for contuse running.
Code:
print "let's wait while looping"
for x = 1 to 10
print "Now at "; x;". Waiting...";
call waitMilliseconds 1000
print "done waiting!"
next x
end
sub waitMilliseconds ms
timer ms, [stopWaiting]
wait
[stopWaiting]
timer 0
end sub
The upper is the official example of TIMER, I said to my self if I want my program to work correctly I must limited my TIMER usage with this example. (it is a delay element)
Sarmed
|
| « Last Edit: Nov 1st, 2015, 3:36pm by SarmedNafi » |
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: goto [loop]
« Reply #9 on: Nov 1st, 2015, 5:15pm » |
|
on Nov 1st, 2015, 3:34pm, SarmedNafi wrote:| Actually LB TIMER is a good delay element, we don't need to use SLEEP. |
|
There are a number of reasons why Sleep is sometimes necessary:
For short delays. Although the TIMER parameter is specified in milliseconds, the shortest delay you can actually achieve is about 10 milliseconds and can be as long as 20 milliseconds:
Code: start = time$("ms")
timer 1, [pause]
wait
[pause]
finish = time$("ms")
timer 0
print "Delay was "; finish-start; " milliseconds"
end
To prevent an 'infinite loop' hogging the CPU. If your program is looping 'doing nothing' it will slow down other processes and can make the PC unresponsive. You should include a Sleep(0) or Sleep(1) in such loops:
Code: calldll #kernel32, "Sleep", 0 as long, r as long
In LB 4 (but not LBB) certain Windows API calls (e.g. the WMLiberty DLL) are incompatible with the WAIT statement, so the replacement code I listed must be used instead (this is not a delay routine):
Code:' replacement for WAIT
[loop]
calldll #kernel32, "Sleep", 1 as long, r as long
scan
goto [loop]
In LB 4 (but not LBB) there is a bug which causes TIMER to break the PROMPT statement, so it may be necessary to use Sleep instead. See this page at the LB Bug Tracker wiki. Richard.
|
|
|
|
SarmedNafi
Junior Member
member is offline


Posts: 93
|
 |
Re: goto [loop]
« Reply #11 on: Nov 1st, 2015, 11:57pm » |
|
Thank you Richard for the wider scope explanation. Thank you Alyce for being here.
However any LB user soon or later will find himself wants to use (for example) keyboard pressing response program, he starts thinking of TIMER then he shocked with the unreliable performance of Liberty Basic, unless Carl will fix it, or he will jump to the Booster LBB (that what I did).
Regards,
|
| « Last Edit: Nov 2nd, 2015, 12:08am by SarmedNafi » |
Logged
|
|
|
|
|