(Redirected from Stack Blocks)

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 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:

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. Do not rely on this, as it depends on the computer's speed.

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

Note Note: Click on a block for more information.

Motion

There are 15 motion stack blocks.

Looks

There are 17 looks stack blocks.

Sound

There are eight sound stack blocks.

Events

Events has only two stack blocks:

Control

There are four control stack blocks.

Sensing

There are three sensing stack blocks.

Variables

There are 11 variable and list blocks.

List

My Blocks

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

  • custom block:: custom

Music Extension

There are six stack blocks in the Music Extension.

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.

Video Sensing Extension

There are two stack blocks in the Video Sensing Extension.

Text to Speech Extension

There are three stack blocks in the Text to Speech Extension.

Micro:bit Extension

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

LEGO MINDSTORMS EV3 Extension

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

LEGO BOOST Extension

There are seven stack blocks in the LEGO BOOST Extension.

LEGO Education WeDo 2.0

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

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) seconds
  • Before/after other Stack blocks
go to (Sprite2 v)
play sound (meow v) until done
point towards (Sprite3 v)
say [Bye.] for (2) seconds
stop [this script v]
forever
if <(loudness) > (30)> then
say [No noises.] for (2) seconds

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:

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

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

Cookies help us deliver our services. By using our services, you agree to our use of cookies.