Stack Block

A **Stack block** is a rectangular block that is shaped to fit above and below other blocks. Stack blocks make up the majority of the blocks available in Scratch, being available in every non-extension category except Operators.

## Execution Process

When 2 stack blocks are connected to form a script their commands will execute in the order from top to bottom. The entire collective stack executes in a single frame. For example, take the following script:

<scratchblocks>
reset timer
move (5) steps
move (4) steps
move (3) steps
move (2) steps
move (1) steps
set [elapsed time v] to (timer)
</scratchblocks>

The entire execution process for this stack of stack blocks will take approximately 0 seconds. Opposed to visualizing the sprite move 5 steps, then 4, etc. the entire motion will be seen in one unified step; the end user will witness what appears to be the sprite move 15 steps, even though it has 5 separate blocks making up the motion. The elapsed time variable will be 0 when the script finishes executing.

Take the following code, now. While it appears to be the same, just using a loop, it actually is not all executed in a single frame this time.

<scratchblocks>
reset timer
set [step move v] to (5)
repeat (5)
move (step move) steps
change [step move v] by (-1)
end
set [elapsed time v] to (timer)
</scratchblocks>

This scenario should have 5 separate motions and should take up 5 frames of the 30-frame-per-second Scratch project. It should take approximately 0.166 seconds to execute. Initially, the sprite moves 5 steps. Then there is a pause because of how the repeat loop works. Then, the sprite moves 4 steps, and so forth. The only method of using a repeat loop without the delay between each cycle is to place the repeat loop inside a custom block that has the "run without screen refresh" option enabled.

### Stack Blocks With Delay

Some stack blocks do execute with a delay, meaning there may be a pause between it and the next block executing. The following blocks have this behavior:

* Wait () Seconds
* Wait Until ()
* Ask () and Wait
* Play Sound () Until Done
* Switch Backdrop to () and Wait

## Blocks

### Motion

There are 15 motion stack blocks.

* <sb>move () steps</sb>
* <sb>turn cw () degrees</sb>, <sb>turn ccw () degrees</sb>

* <sb>go to [ v]</sb>
* <sb>go to x: () y: ()</sb>
* <sb>glide () secs to x: () y: ()</sb>
* <sb>glide () secs to [ v]</sb>

* <sb>point in direction ()</sb>
* <sb>point towards [ v]</sb>

* <sb>change x by ()</sb>
* <sb>set x to ()</sb>
* <sb>change y by ()</sb>
* <sb>set y to ()</sb>

* <sb>if on edge, bounce</sb>
* <sb>set rotation style [ v]</sb>

### Looks

There are 17 looks stack blocks.

* <sb>say [] for () seconds</sb>
* <sb>say []</sb>
* <sb>think [] for () seconds</sb>
* <sb>think []</sb>

* <sb>switch costume to [ v]</sb>/<sb>switch backdrop to [ v]</sb>
* <sb>switch backdrop to [ v] and wait</sb>
* <sb>next costume</sb>/<sb>next backdrop</sb>

* <sb>change size by ()</sb>
* <sb>set size to ()%</sb>

* <sb>change [ v] effect by ()</sb>
* <sb>set [ v] effect to ()</sb>
* <sb>clear graphic effects</sb>

* <sb>show</sb>
* <sb>hide</sb>

* <sb>go to [ v] layer</sb>

* <sb>go [ v] () layers</sb>

### Sound

There are eight sound stack blocks.

* <sb>play sound [ v] until done</sb>
* <sb>start sound [ v]</sb>
* <sb>stop all sounds</sb>

* <sb>change [ v] effect by ()::sound</sb>
* <sb>set [ v] effect to ()::sound</sb>
* <sb>clear sound effects</sb>

* <sb>change volume by ()</sb>
* <sb>set volume to () %</sb>

### Events

Events has only two stack blocks:

* <sb>broadcast [ v]</sb>
* <sb>broadcast [ v] and wait</sb>

### Control

There are four control stack blocks.

* <sb>wait () seconds</sb>
* <sb>wait until <></sb>
* <sb>create clone of [ v]</sb>
* <sb>stop [other scripts in sprite v] // If "all" or "this script" is selected in the drop-down menu, this block becomes a Cap block.</sb>

### Sensing

There are three sensing stack blocks.

* <sb>ask [] and wait</sb>
* <sb>set drag mode [ v]</sb>
* <sb>reset timer</sb>

### Variables

There are 11 variable and list blocks.

* <sb>set [ v] to ()</sb>
* <sb>change [ v] by ()</sb>
* <sb>show variable [ v]</sb>
* <sb>hide variable [ v]</sb>

#### List

* <sb>add [] to [ v]</sb>

* <sb>delete () of [ v]</sb>
* <sb>delete all of [ v]</sb>
* <sb>insert [] at () of ()</sb>
* <sb>replace item () of [ v] with ()</sb>

* <sb>show list [ v]</sb>
* <sb>hide list [ v]</sb>

### My Blocks

The My Blocks area allows the user to make their own stack blocks.

* <sb>custom block :: custom</sb>

### Music Extension

There are six stack blocks in the Music Extension.

* <sb>play drum [ v] for () beats</sb>
* <sb>rest for () beats</sb>
* <sb>play note () for () beats</sb>
* <sb>set instrument to [ v]</sb>
* <sb>set tempo to ()</sb>
* <sb>change tempo by ()</sb>

### Pen Extension

There are nine blocks in the Pen Extension, and all of them are stack blocks. This is the most stack blocks for any extension.

* <sb>erase all</sb>
* <sb>stamp</sb>
* <sb>pen up</sb> / <sb>pen down</sb>
* <sb>set pen color to ()</sb>
* <sb>change pen [ v] by ()</sb>
* <sb>set pen [ v] to ()</sb>
* <sb>change pen size by ()</sb>
* <sb>set pen size to ()</sb>

### Video Sensing Extension

There are two stack blocks in the Video Sensing Extension.

* <sb>turn video [ v]</sb>
* <sb>set video transparency to ()</sb>

There are no stack blocks in the Translate Extension.

### Micro:bit Extension

There are three stack blocks in the micro:bit Extension.

* <sb>display [ v] :: microbit</sb> / <sb>display () :: microbit</sb>
* <sb>clear display :: microbit</sb>

### LEGO MINDSTORMS EV3 Extension

There are four stack blocks in the LEGO MINDSTORMS EV3 Extension.

* <sb>motor [ v] turn this way for () seconds :: ev3</sb>
* <sb>motor [ v] turn that way for () seconds :: ev3</sb>
* <sb>motor [ v] set power ()%::ev3</sb>
* <sb>beep note () for () secs::ev3</sb>

### LEGO Education WeDo 2.0

There are six stack blocks in the LEGO Education WeDo 2.0 Extension.

* <sb>turn [ v] on for () seconds :: wedo</sb>
* <sb>turn [ v] on :: wedo</sb> / <sb>turn [ v] off :: wedo</sb>
* <sb>set [ v] power to () :: wedo</sb>
* <sb>set [ v] direction to [ v] :: wedo</sb>
* <sb>set light color to () :: wedo</sb>

## Shape

Stack blocks are fitted with a puzzle-piece like shape; the top has a notch and the bottom has a bump. Because of this shape, scripts can stretch on and on

 the block tessellates.

Their shape allows them to be placed in the following areas:

* After Hat blocks

<scratchblocks>when gf clicked
say [Hi.] for (2) seconds</scratchblocks>

* Before/after other Stack blocks

<scratchblocks>go to [Sprite2 v]
play sound [meow v] until done
point towards [Sprite3 v]</scratchblocks>

* Before Cap blocks

<scratchblocks>say [Bye.] for (2) seconds
stop [this script v]</scratchblocks>

* Inside C blocks

<scratchblocks>forever
if <(loudness) > (30)> then
say [No noises.] for (2) seconds</scratchblocks>

## Use

As Stack blocks are shaped to allow blocks above and below them, they are used almost everywhere in a script; most scripts have a Stack block in them. An example script:

<scratchblocks>
when flag clicked
repeat until <(do\_Stop) = [1]>
move (10) steps
change [color v] effect by (25)
play sound [meow v] until done
if <touching [edge v]?> then
say [Done!] for (2) seconds
stop [this script v]
end
end
</scratchblocks>

Note how the Stack blocks are used in the script

 they make up all the commands.

de:Blockform = Stapel-Blöcke
ja:スタックブロック
es::Bloque apilable