Pausing Script Execution

Once started, scripts execute without pause until they are done. However, sometimes you need to temporarily pause a script’s execution for a specified period. The code block that you need to use in this type of situation is shown in Figure 9.2.

Figure 9.2. Using this control block, you can pause script execution for as long as necessary.


This code block adds brief pauses to your Scratch applications. For example, you might want to pause a script’s execution for a second or two after the player scores a point. This brief pause would allow the player a moment to review the score and to get ready for the next point. Another reason for pausing a script’s execution is to help manage the playback of audio files, as demonstrated in the following example:

Here, you see a script that plays two audio files. In order to allow the first audio file time to play back, the script is paused for two seconds, after which execution resumes, and the second audio file is played. If you were to remove the control block that pauses the script from this example, both audio files would play simultaneously, interfering with one another.

Tip

It you want to continuously play an audio file without pausing a script’s execution, consider putting the code statements that are responsible for audio file playback in their own script and adding that script to the stage.


Note

The control block shown in Figure 9.3 also pauses script execution, waiting until a specified condition becomes true. This code block is covered a little later in this chapter, when conditional programming logic is discussed.

Figure 9.3. This code block provides another way of conditionally pausing script execution.



..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.220.114