The general shape of a 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 category except Operators and PicoBoard Blocks.

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:

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

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.

Note Note: Extremely long and intensive scripts could take a long time to process and may actually have a notable enough elapsed time.

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.

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)

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:

Blocks

There are 77 stack blocks in Scratch 2.0, including extensions, click on a block to find out more.

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:

when gf clicked
say [Hi.] for (2) secs
  • Before/after other Stack blocks
go to [Sprite2 v]
play sound [meow v] until done
point towards [Sprite3 v]
say [Bye.] for (2) secs
stop [this script v]
forever
if <(loudness) > (30)> then
say [No noises.] for (2) secs

Use

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

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) secs
stop [this script v]
end
end

Note how the Stack blocks are used in the script — they make up all the commands.

Document stub.png
This page has bad source code style. If you can improve it according to Scratch Wiki:Style Guide, please do! (September 2018)
Specifically, this page: