Jump to content

BSL:Manual: Difference between revisions

1,130 bytes added ,  1 November 2017
exploring and documenting schedule ... repeat ... every ...
m (sleep(f60) note)
(exploring and documenting schedule ... repeat ... every ...)
Line 639: Line 639:


  schedule dprint("Is this annoying yet?") repeat 50 every 20;
  schedule dprint("Is this annoying yet?") repeat 50 every 20;
This seem to be equivalent to a simplified for loop in a C style programming language (equivalent code in C style for loop is showed next):
for(int i=0; i!=repeat_value; i++){
    function_name();
    wait(every_value);
}
<u>infinite loop</u>
To create an infinite loop you can use 0 (or a negative number like -1) as repeat value:
schedule dprint("Is this annoying yet?") repeat 0 every 20; # repeats forever
<u>using as replacement for recursive functions</u>
schedule ... repeat ... every ... is a very useful function and can be used to replace recursive functions that call themselves n times using fork function(), for example:
func void hey(){
    dmsg("hey");
    sleep(1);
    fork hey();
}
func void main () {
    fork hey();
}
can be replaced by:
func void hey(){
    dmsg("hey");
}
schedule hey() repeat 0 every 60;
Note: (60 ticks <=> 60 frames <=> 1 second <=> sleep(1) [ <=> means equivalent ]
Recursive functions using fork have also the limitation of being called at the minimum of 60 frames per second where the schedule ... repeat ... every ... can be called down to 1 frame per second.


==Variables==
==Variables==
489

edits