Terminating Script Execution

The last two control blocks offered by Scratch are shown in Figure 9.7. These code blocks programmatically halt script execution within your Scratch applications.

Figure 9.7. Using these code blocks, you can halt the execution of any or all scripts within an application.


Using the first of these two control blocks, you can halt the execution of the scripts in which the code block is placed, as demonstrated in the following example:

Here, the script checks to see if the value assigned to a variable named Counter is equal to 3, and if it is, an audio file is played. If Counter is not equal to 3, then a different audio file is played, and the script’s execution is halted. Halting a script this way forces its immediate termination, even if the script contains additional code blocks that have not been executed.

Using the second control block shown in Figure 9.7, you can not only halt the execution of the current script, but you can also halt the execution of every script in the application. For example, the following script executes a loop three times and then halts the execution of every script in the application in which it resides.

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

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