Author |
Topic: WAIT Command without halting? (Read 853 times) |
|
Usama Amin
New Member
member is offline


Gender: 
Posts: 18
|
 |
WAIT Command without halting?
« Thread started on: Oct 21st, 2012, 09:20am » |
|
hi again guys, is there a way to make a specific part of the program wait without halting the whole program... https://www.dropbox.com/s/y9a9fkhy0qirmek/Space%20Invaders.bbc this is my program, i am talking about line 450 to 520. Thanks again
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: WAIT Command without halting?
« Reply #1 on: Oct 21st, 2012, 3:05pm » |
|
on Oct 21st, 2012, 09:20am, Usama Amin wrote:is there a way to make a specific part of the program wait without halting the whole program... |
|
Usually only a small delay, for example WAIT 0 or WAIT 1, is sufficient to keep your program's CPU usage low and allow other processes to run. Then you can check for a certain time having elapsed by, for example, testing the TIME pseudo-variable:
Code: Task1% = TIME
Task2% = TIME
REPEAT
WAIT 1 : REM Release the CPU to other processes
IF (TIME - Task1%) > 100 THEN
Task1% = TIME
REM Put here things which need to be done
REM once every second
ENDIF
IF (TIME - Task2%) > 10 THEN
Task2% = TIME
REM Put here things which need to be done
REM ten times every second
ENDIF
UNTIL FALSE Other ways you can tackle this are to use the ON TIME interrupt or the TIMERLIB library.
Richard.
|
|
Logged
|
|
|
|
Usama Amin
New Member
member is offline


Gender: 
Posts: 18
|
 |
Re: WAIT Command without halting?
« Reply #2 on: Oct 21st, 2012, 3:25pm » |
|
Thanks again richard
|
|
Logged
|
|
|
|
Usama Amin
New Member
member is offline


Gender: 
Posts: 18
|
 |
Re: WAIT Command without halting?
« Reply #3 on: Oct 21st, 2012, 3:30pm » |
|
So if i used:
Task1% = TIME Task2% = TIME REPEAT WAIT 1 : REM Release the CPU to other processes IF (TIME - Task1%) > 100 THEN Task1% = TIME PRINT "hello" ENDIF UNTIL FALSE
It would print hello once every second?
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: WAIT Command without halting?
« Reply #4 on: Oct 21st, 2012, 5:02pm » |
|
on Oct 21st, 2012, 3:30pm, Usama Amin wrote:So if i used [code snipped] It would print hello once every second? |
|
Why are you asking when it takes only a moment to try it? One of the advantages of an interpreted language like BBC BASIC is that you get instant results - copy-and-paste the code into the BB4W editor and click 'Run'!
Richard.
|
|
Logged
|
|
|
|
Usama Amin
New Member
member is offline


Gender: 
Posts: 18
|
 |
Re: WAIT Command without halting?
« Reply #5 on: Oct 21st, 2012, 5:03pm » |
|
It didnt work
|
|
Logged
|
|
|
|
Usama Amin
New Member
member is offline


Gender: 
Posts: 18
|
 |
Re: WAIT Command without halting?
« Reply #6 on: Oct 21st, 2012, 5:04pm » |
|
Sorry, Task1% = TIME Task2% = TIME REPEAT WAIT 1 : REM Release the CPU to other processes IF (TIME - Task1%) > 100 THEN Task1% = TIME PRINT "hello" ENDIF UNTIL FALSE This worked but wehen i tried incorporating it in my program it didnt
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: WAIT Command without halting?
« Reply #7 on: Oct 21st, 2012, 9:26pm » |
|
on Oct 21st, 2012, 5:04pm, Usama Amin wrote:This worked but wehen i tried incorporating it in my program it didnt |
|
I'm afraid that's your problem! Use the debugging tools available to you to find out why it's not working.
Richard.
|
|
Logged
|
|
|
|
Usama Amin
New Member
member is offline


Gender: 
Posts: 18
|
 |
Re: WAIT Command without halting?
« Reply #8 on: Oct 22nd, 2012, 4:43pm » |
|
I got it working thatnks for the advice Richard!
|
|
Logged
|
|
|
|
|