From Test-Scratch-Wiki

Translate: - English - Türkçe - 中文 - 한국어 
"Program" redirects here. For an explanation of the process of writing programs with code, see Programming.
當 @greenflag 被點擊
重複直到 <(timer) > [10]> 
  定位到 [滑鼠游標 v] 位置
end
說出 [Meow!] (3) 秒
An example script.

A script is a collection or stack of 積木 that all interlock with one another. The blocks and their order are very important, as they determine how 角色 interact with each other and the 背景. Sometimes, 注釋 are attached to scripts to explain what certain blocks do and what the script's purpose is.

用法

Scripts are easy to work with. Some "rules" are as follows:

  • To create a script, one simply has to drag blocks out of the 積木選擇區 and assemble them.
  • To assemble blocks, they must be dragged on, below, or in another block. (Except for 半圓形積木.)
  • To disassemble blocks, they must be dragged apart.
  • To remove a script, drag it into any of the 積木選擇區, or right-click the hat block and press delete.
  • To start a single script just click on it.

Scripts can be edited in the scripts tab of every 角色 and the 舞台.

Structure

Every block shape is designed so that it can do one or more of the following:

  • Start a script
  • Add to the end of a script
  • End a script
  • Fit inside other blocks.
  • Contain other blocks.

Because of that, blocks can be assembled to create a script like a jigsaw puzzle. This prevents syntax errors.

定義

A script is defined within the Scratch program as one or a set of blocks that begins with a 半圓形積木. Even a single block can qualify. However, scripts are usually referred to as sets of blocks that consist of at least two blocks.

程式錯誤

Archive.png This article or section documents a feature not included in the current version of Scratch (2.0). It is only useful from a historical perspective.
On error, the script turns red.

When using previous versions, when putting certain blocks together, it is sometimes possible to make an impossible script (impossible meaning that it cannot function, see the below example.) When impossible scripts are run, in development mode, the script is outlined in red, the trouble-causing block colored red, and the whole script is paused. Online, the player simply ignores it and moves on if possible. In the current 2.0, if you have an error like the one shown, the script will just stop.

Errors are usually caused mathematically, such as when a script tries to divide by zero or find the square root of negative one. Trigonometric errors are also common. Other common errors are caused by using a 積木 only available in 角色 in the 舞台, or when an nonexistent 項目 of a 清單 is being accessed.

For a tutorial on fixing scripts like this, see the article 腳本的偵錯.

參見