BBC BASIC for Windows
Programming >> Graphics and Games >> WAIT Command without halting?
http://bb4w.conforums.com/index.cgi?board=graphics&action=display&num=1350811247

WAIT Command without halting?
Post by Usama Amin 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
Re: WAIT Command without halting?
Post by admin 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.
Re: WAIT Command without halting?
Post by Usama Amin on Oct 21st, 2012, 3:25pm

Thanks again richard smiley
Re: WAIT Command without halting?
Post by Usama Amin 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?
Re: WAIT Command without halting?
Post by admin 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.
Re: WAIT Command without halting?
Post by Usama Amin on Oct 21st, 2012, 5:03pm

It didnt work sad
Re: WAIT Command without halting?
Post by Usama Amin 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 cry
Re: WAIT Command without halting?
Post by admin 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 cry

I'm afraid that's your problem! Use the debugging tools available to you to find out why it's not working.

Richard.

Re: WAIT Command without halting?
Post by Usama Amin on Oct 22nd, 2012, 4:43pm

I got it working thatnks for the advice Richard! grin