Script

For other uses, see Program (disambiguation).
<scratchblocks>when gf clicked
repeat until <(timer) > [10]>

```
 go to (mouse-pointer v)

```

end

say [Meow!] for (3) secs</scratchblocks>
A **script** is a collection, or "stack", of blocks that all interlock with one another. The blocks and their order are very important, as they determine how sprites interact with each other and the Stage. Sometimes, comments are attached to scripts to explain what certain blocks do and what the script's purpose is.

## Use

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

* To create a script, drag blocks out of the Block Palette and assemble them.
* To assemble blocks, drag them on top of, below, or into another block. (Different blocks can do only some of these things.)
* To disassemble blocks, drag them apart.
* To remove a script, a portion of a script, or a block, drag it into the block palette, or right-click the top block in the script portion and choose "Delete Blocks".
* To start a single script, simply click on it.

Scripts can be edited in the scripts tab of every sprite and the Stage.

## Structure

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

* Hat Blocks start a script. These can only be placed on top of stack blocks, C blocks, or cap blocks.
* Stack Blocks add to the end of a script, and can also be inserted elsewhere. These can be placed on top of or below other stack blocks, inside a C block, below a hat block, or on top of a cap block.
* Cap Blocks end a script. These can only be placed below stack blocks, C blocks, or cap blocks.
* Reporter Blocks and Boolean Blocks report values to be used by other blocks. These can only be placed inside other blocks, and often can be placed inside themselves.
* Various blocks of the types above can contain reporter blocks and/or Boolean blocks.

In this way, blocks can be assembled like a jigsaw puzzle to create scripts. This removes the possibility of syntax errors.

## Definition

A script is defined within the Scratch program as one or a set of blocks that begins with a Hat Block. A single block counts as a script; however, common usage tends to use "script" to refer to at least two blocks.

## Script Errors

 File:ScriptError.png
When using previous versions, when putting certain blocks together, it is sometimes possible to make an impossible script, meaning that it cannot function. When impossible scripts are run in development mode, the script is outlined in red, the trouble-causing block is colored red, and the whole script is paused. Online, including in Scratch 3.0, the player simply ignores it and moves on if possible.

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 block only available in sprites in the stage, or when an non-existent item of a list is being accessed.

For help on fixing scripts like this, see the article Debugging Scripts.

## Script Fragments

A script fragment, also known as an orphaned script, is a script that is "incomplete" because it is missing a hat block. A script fragment will not run during normal execution of a project, because nothing triggers the code. It is possible to run a script fragment by clicking on it in the Project Editor. They are commonly used to create thumbnails because of the ability to show a sprite that isn't visible while normally running the project. Script fragments can be stored in the Backpack, and can easily be dragged underneath a hat to run the code. Any single blocks without a hat in the editor are also script fragments.

## See Also

* Blocks
* How to Organize Your Scripts
* Code Area

de:Skript
ru:Скрипт
ja:スクリプトid:Skrip