(Redirected from Stack Blocks)
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: | 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:
switch backdrop to ( v) and wait
play sound ( v) until done
wait () seconds
wait until <>
ask () and wait
Blocks
Note: | Click on a block for more information. |
Motion
There are 15 motion stack blocks.
move () steps
turn cw () degrees
turn ccw () degrees
go to ( v)
go to x: () y: ()
glide () secs to ( v)
glide () secs to x: () y: ()
point in direction ()
point towards ( v)
change x by ()
set x to ()
change y by ()
set y to ()
if on edge, bounce
set rotation style [ v]
Looks
There are 17 looks stack blocks.
say [] for () seconds
say []
think [] for () seconds
think []
switch costume to ( v)
switch backdrop to ( v)
switch backdrop to ( v) and wait
next costume
next backdrop
change size by ()
set size to ()%
change [ v] effect by ()
set [ v] effect to ()
clear graphic effects
show
hide
go to [ v] layer
go [ v] () layers
Sound
There are eight sound stack blocks.
play sound ( v) until done
start sound ( v)
stop all sounds
change [ v] effect by ()::sound
set [ v] effect to ()::sound
clear sound effects
change volume by ()
set volume to () %
Events
Events has only two stack blocks:
Control
There are four control stack blocks.
wait () seconds
wait until <>
stop [other scripts in sprite v] // If "all" or "this script" is selected in the drop-down menu, this block becomes a Cap block.
create clone of [ v]
Sensing
There are three sensing stack blocks.
Variables
There are 11 variable and list blocks.
List
add [] to [ v]
delete () of [ v]
delete all of [ v]
insert [] at () of [ v]
replace item () of [ v] with ()
show list [ v]
hide list [ v]
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.
play drum ( v) for () beats
rest for () beats
play note () for () beats
set instrument to ( v)
set tempo to ()
change tempo by ()
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.
erase all
stamp
pen up
pen down
set pen color to ()
change pen ( v) by ()
set pen ( v) to ()
change pen size by ()
set pen size to ()
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.
motor ( v) turn this way for () seconds:: ev3
motor ( v) turn that way for () seconds:: ev3
motor ( v) set power ()%
beep note () for () secs
LEGO BOOST Extension
There are seven stack blocks in the LEGO BOOST Extension.
turn motor ( v) for () seconds
turn motor ( v) for () rotations
turn motor ( v) on
turn motor ( v) off
set motor ( v) speed to ()%
set motor ( v) direction ( v)
set light color to ()::boost
LEGO Education WeDo 2.0
There are six stack blocks in the LEGO Education WeDo 2.0 Extension.
turn ( v) on for () seconds
turn ( v) on
turn ( v) off
set ( v) power to ()
set ( v) direction to ( v)
set light color to ():: wedo
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
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)
- Before Cap blocks
say [Bye.] for (2) seconds stop [this script v]
- Inside C blocks
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.