Image bm161.GIF Wait
Program Control
 
The wait command causes to pause the program execution for a preset time. This time is specified in seconds. If no value is entered, the program will wait for 0.055 seconds.
 
The real waiting time need not correspond to the desired time exactly. The program timing depends on the computer type and on the operational system. For example, for the PC computers the nominal time resolution is 0.055 seconds, the accuracy fluctuating roughly between 0.4 and 0.6 seconds (depending on the operational system utilized and the number of other running programs). If an exact timing is necessary, a function for time operation must be used.
 
The wait command is not only helpful for program stopping for a given period. The Windows environment is a multitask one, which means that several programs may be performed at a time. To coordinate the cooperation of the running programs it is necessary that the program not requiring any service passes the control to other programs so that those programs may perform their function. For this purpose the wait command is intended. If no further program service is urgently needed (i.e. all operations are executed and the program is waiting for another step), it is useful to insert the wait command at least for the minimum time period of 0.05 seconds instead of waiting in the loop. Albeit a program from the Peter environment passes the control to the system automatically, a program that is not written properly can overload the system unnecessarily.
 
There are several cases, when it is not necessary to insert the wait commands: when using the step commands for Peter and Lucy (including waiting for completion of the previous moving) and commands for input a character or key from the keyboard with waiting.
 
Another function of the wait command (including the default waiting according to the previous paragraph) is the execution of the program internal services. The services in question concern the sprites' motion and animation, sound and music playback, mouse service and the service of the display repainting. During the wait command timing and possible services of these functions are done. If the wait command is not executed, only automatic synchronization of the internal services is carried out, which, however, may not either be quick enough (the display repaint is jerky) or it may not be carried out at suitable time (the display repaint is done between two graphic commands and therefore the display is blinking).
 
For time consuming programs a special modification of the wait command is available: the waiting time is set to zero. In this case no waiting takes place, the control is passed over to the system only for the shortest time necessary, the timing of the internal services being done fully. A program having this waiting modification works with almost maximal speed, the repainting and other internal services working properly, and the cooperation with the system and other programs being at the same time ensured, too.

Full Html Context Help of The Peter - Gemtree Software & Children Programming