We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Scratch

From Esolang
Jump to navigation Jump to search
This article is not detailed enough and needs to be expanded. Please help us by adding some more information.
Scratch
Paradigm(s) Event-driven
Designed by Resnick, Kafai, Maeda, et al.
Appeared in 2003
Computational class Turing-complete
Reference implementation Scratch 1.4, Scratch 2.0, Scratch 3.0
Major implementations Turbowarp (mod)

PenguinMod (mod of Turbowarp)

Scratch Everywhere!
Influenced Snap!/BYOB, ScratchJr
File extension(s) .sb3, .sb2, .sb, .sprite3, .sprite2, .sprite

Scratch is a visual programming language created in 2003 by a collaboration between MIT Media Lab's Lifelong Kindergarten Group (LLK) and UCLA, led by Mitchel Resnick and Yasmin Kafai, for teaching children how to program. It uses blocks, and has a 2D canvas (the "Stage") where sprites are on.

Sprites and the Stage

Sprites are the actors in a project. They house costumes, sounds, and scripts which allow them to interact with the Stage and each other and perform tasks. A costume is an image which a sprite displays.

The "Stage" is the space in which sprites reside. It is a 480x360-pixel canvas with the center being (0, 0), the upper-right corner being (240, 180), and the lower-left corner being (-240, -180). Just like sprites, the Stage also houses costumes (called backdrops), sounds, and scripts.

Values

Scratch has 3 types of values: numbers, Booleans, and strings. However, they are not mutually exclusive and can be freely coerced into another type. For example 123456789 may be interpreted as a string by (length of ()) and <join () ()>, but may be interpreted as a number instead by (() + ()).

Variables

Scratch has three types of variables: for all sprites, for this sprite only, and cloud variables. Variables that are for all sprites are like global variables, any sprite can access them. Variables that are for this sprite only can only be accessed within this sprite (with the exception of the usage of the ((thing v) of (thing v)) block) and clones will each get their own copy.

Cloud variables are special in that their value is stored in a server, which means that one user changing a cloud variable will have all other users with that project open see that change. However, they are limited to only 256 characters, may only store numbers, and are updated only 10 times per second. Cloud variables are accessible by all sprites and the Stage andusually have a โ˜๏ธ symbol prefixing their name to distinguish them from non-cloud variables. Additionally, New Scratchers (newly created Scratch accounts with not much activity yet) are unable to use the cloud functionality of cloud variables.

Creating a new project will make a variable named "my variable".

Lists

In Scratch, lists are like variables that can store multiple values. Unlike typical languages such as Python or C++, Scratch does not consider lists to be first-class values like strings and numbers are. Lists have a maximum size of 200,000 elements.

Lists can be for all sprites or for this sprite only, however cloud lists do not exist and are not a planned feature in Scratch.

Scratch also starts indexing at 1 instead of zero to line up with common intuition as most non-programmers and some programmers start counting at 1 instead of 0.

Blocks

By default, a new empty project in Scratch has 9 (technically 10) block categories. Each category is dedicated to a specific function, for example Motion blocks are related to the sprite's position and orientation while Operators is related to mathematical operators.

Though Scratch is a visual programming language, it also has a semi-official text format for illustrative purposes (such as this wiki page) only. (text) is a reporter, <text> is a Boolean reporter, (text v) is a dropdown that can be overridden with another reporter, and [text v] is a dropdown that cannot be overridden.

Motion

The Motion category contains blocks related to the sprite's position and orientation on the Stage. This category is not available in the Stage itself as it is stationary. There are currently 18 blocks in this category.

Every sprite has an associated X and Y position and direction. A direction of 0 degrees is facing upwards, a direction of 90 degrees is facing rightwards, a direction of 180 degrees is facing down, and a direction of -90 degrees is facing left and upside-down.

There are rotation styles which determine what a sprite looks like when it is rotated. A rotation style of "all around" is self-explanatory: the sprite is always facing in its direction. A rotation style of "left-right" makes the sprite face 90 degrees if its direction is to the right, and -90 degrees if its direction is to the left. A rotation style of "don't rotate" makes the sprite always appear to face 90 degrees. Rotation styles are purely visual, they do not affect a sprite's actual direction in any way.

Block Description
move (amount) steps Moves this sprite amount pixels (steps)
go to [random position v]

go to [mouse-pointer v]
go to [Sprite v]

Sets this sprite's position to either a random position within the Stage, the mouse pointer's position, or the given sprite's position.
go to x: (X) y: (Y) Sets the sprite's position to the given values.
glide (duration) secs to [random position/mouse pointer/Sprite v] Linearly interpolates this sprite's position to the target position as of the start of invoking this block over the course of duration seconds.
glide (duration) secs to x: (X) y: (Y) Linearly interpolates this sprite's position towards the given coordinates over the course of duration seconds.
point in direction (dir) Sets this sprite's direction to dir degrees.
point towards [mouse-pointer v]

point towards [Sprite v]

Points this sprite towards either the mouse pointer or the given sprite's position.
change x by (amount) Changes this sprite's X position by amount with respect to sprite fencing.
set x to (X) Sets this sprite's X position to X with respect to sprite fencing.
change y by (amount) Changes this sprite's Y position by amount with respect to sprite fencing.
set y to (Y) Sets this sprite's Y position to Y with respect to sprite fencing.
if on edge, bounce Reflects this sprite's direction if it is touching the edges of the stage.
set rotation style [left-right v]

set rotation style [don't rotate v]
set rotation style [all around v]

Sets this sprite's rotation style to the given rotation style.
(x position) Returns the X position of this sprite.
(y position) Returns the Y position of this sprite.
(direction) Returns the rotation of this sprite. This is a number in the range [-180, 180].

Looks

The Looks category contains blocks related to the sprite's appearance. There are currently 20 blocks in this category.

Sprites have 7 visual effects: color, fisheye, whirl, pixelate, mosaic, brightness, and ghost. Color is a hue shift. Fisheye is a fisheye lens effect based on the center of the sprite's costume. Whirl is a whirl or spiral effect. Pixelate pixelates the sprite. Mosaic is a mosaic effect. Brightness determines the brightness of the sprite, with -100 being pitch-black, 0 being normal brightness, and 100 being pure white. Ghost is the transparency of the sprite, with 0 being fully opaque and 100 being fully transparent. Setting ghost to 100 while showing the sprite is different from just hiding the sprite, as hidden sprites cannot interact with other sprites.

Sprites also follow a layering system, with sprites on higher layers being drawn in front of sprites on lower layers.

Block Description Stage
say [text] for (duration) seconds Stalls the current script and makes this sprite say text inside a text bubble for duration seconds. No
say [text] Makes this sprite say text inside a text bubble forever or until either the script or project has been stopped. If text is empty, then if the sprite is currently saying something then it stops saying that. Overrides think. No
think [text] for (duration) seconds Stalls the current script and makes this sprite say text inside a thought bubble for duration seconds. No
think [text] Makes this sprite say [text] inside a thought bubble forever or until either the script or the project has been stopped. If text is empty, then if the sprite is currently saying something then it stops saying that. Overrides say. No
switch costume to (costume v) Switches this sprite's costume to costume. No
next costume Switches this sprite's costume to the next costume in line. The last costume wraps around to the first costume. No
switch backdrop to (backdrop v) Switches the Stage's backdrop to backdrop. Yes
next backdrop Switches the Stage's backdrop to the next backdrop in line. The last backdrop wraps around to the first backdrop. Yes
change size by (amount) Changes this sprite's size by amount with respect to size fencing. No
set size to (amount) % Sets this sprite's size to amount% with respect to size fencing. No
change [effect v] effect by (amount) Changes this sprite's effect effect by amount. Yes
set [effect v] effect to (amount) Sets this sprite's effect effect by amount. Yes
clear graphic effects Sets all of this sprite's visual effects to zero. Yes
show Shows this sprite. This means the sprite is visible and will be able to be detected by other sprites with the Sensing blocks. No
hide Hides this sprite. This means the sprite is invisible and will not be able to be detected by other sprites with the Sensing blocks. No
go to [front/back v] layer Sends this sprite to either the front or the back layer. No
go [forward/backward v] (layers) layers Sends this sprite either forwards or backwards by layers layers. No
(costume [number/name v]) Returns this sprite's current costume's number or name. No
(backdrop [number/name v]) Returns the Stage's current backdrop's number or name. Yes
(size) Returns this sprite's size. For example, a sprite with 100% size will have this return 100. No

Sounds

The Sounds category contains blocks related to playing sounds. Currently, there are 9 blocks in this category.

Block Description
play sound [sound v] until done Plays the sound sound and hangs the current script until it finishes. Can be interrupted by stop all sounds.
start sound [sound v] Plays the sound sound without hanging the current script.
stop all sounds Stops all sounds that are currently playing in the project.
change [pitch v] by (amount)

change [pan left/right v] by (amount)

Changes the given sound effect by amount.
set [pitch v] to (amount)

set [pan left/right v] to (amount)

Sets the given sound effect to amount.
clear sound effects Resets the sound effects.
change volume by (amount) Changes the volume of this sprite by amount.
set volume to (amount) Sets the volume of this sprite to amount.
(volume) Returns the volume of this sprite. It is a number in the range [0, 100].

Events

The Events category contains blocks related to sending and receiving events, which are a primary paradigm of Scratch. Currently, there are 8 blocks in this category.

Block Description
when flag clicked Hat block that runs when the green flag is clicked.
when [key v] key pressed Hat block that runs its script when the key key is pressed. If the key is either the up or down arrows, then this will also detect mouse scrolling.
when this sprite clicked Hat block that runs its script when this sprite is clicked.
when backdrop switches to [backdrop v] Hat block that runs its script when the Stage's backdrop switches to backdrop.
when [loudness v] > (amount)

when [timer v] > (amount)

Hat block that runs its script when the value of either (loudness) or (timer) is greater than amount.
when I receive [message v] Hat block that runs its script when the event message is broadcasted.
broadcast [message v] Broadcasts the event message to all sprites and the Stage.
broadcast [message v] and wait Broadcasts the event message to all sprites and the Stage and hangs the current script until all scripts responding to the broadcast have finished running.

Control

The Control category contains blocks related to control flow. Currently, there are 11 blocks in this category.

Block Description
wait (duration) seconds Hangs the current script for duration seconds.
repeat (amount)
  ...
end
Repeats the code inside it amount times. amount is considered only once at the start of the loop, so even if it changes the loop will still loop the original amount of times.
forever
  ...
end
Runs the code inside it forever. However, it waits for one frame before running the next iteration unless this is inside a "run without screen refresh" custom block.
if <condition> then
  ...
end
An if statement.
if <condition> then
  ...
else
  ...
end
An if-else statement. Unlike "traditional" programming languages however, else-if statements do not exist and thus must be done like so:
if <condition 1> then
  ...
else
  if <condition 2> then
    ...
  else
    if <condition 3> then
      ...
    else
      ...
    end
  end
end
wait until <condition> Hangs the current script until condition is true.
repeat until <condition>
  ...
end
Repeats the code inside it until condition is false, in short the opposite of a while loop in "traditional" programming languages. However, it waits for one frame before running the next iteration unless this is inside a "run without screen refresh" custom block.
stop [all v]

stop [this script v]
stop [other scripts in sprite v]

Self-explanatory.
when I start as a clone Hat block that starts a script for a clone. When a clone of a sprite is created, it gains its own separate state (position, rotation, costume, effects, sprite-only variables and lists) and runs all when I start as a clone blocks for itself.
create clone of (myself v)

create clone of (Other Sprite v)

Creates a clone of either this sprite (myself) or another sprite.
delete this clone Self-explanatory.

Sensing

The Sensing category contains blocks related to sensing the state of the project and other sprites.

Block Description Stage
<touching (mouse-pointer v)?>

<touching (edge v)?>
<touching (Sprite v)?>

Returns whether this sprite is touching either the mouse pointer, the edges of the stage, or the given sprite. No
<touching (color)?> Returns whether this sprite is touching the given color. This is not exact as Scratch only tests the top 5 bits of the red and green channels and the top 4 bits of the blue channel.[1] No
<color (color 1) is touching (color 2)?> Returns whether color 1 on this sprite's costume is touching color 2 Just like <touching (color)?>, this is only approximate.[1] No
(distance to (mouse-pointer v))

(distance to (Sprite v))

Returns the distance (in pixels) of this sprite to either the mouse pointer or the given sprite. No
ask [prompt] and wait Hangs the current script and reads a line of input from the user. Once the user has entered their answer, the built-in sprite-only (answer) variable is set to what the user entered. Additionally, if this is running on a sprite and the sprite is shown, a text bubble containing prompt is shown. Otherwise, prompt is shown above the answer box instead. Yes
(answer) A built-in sprite-only variable containing the user's input. This is initially set to the empty string. Yes
<key (key v) pressed?> Returns whether the key key is currently being pressed. Yes
<mouse down?> Returns whether the left, middle, or right mouse buttons are currently down. Yes
(mouse x) Returns the X position of the mouse pointer, clamped to be within the Stage's bounds or the range [-240, 240]. Yes
(mouse y) Returns the Y position of the mouse pointer, clamped to be within the Stage's bounds or the range [-180, 180]. Yes
set drag mode [draggable v]

set drag mode [not draggable v]

Sets whether this sprite can be dragged or not. This is different from sprites being able to be dragged around in the editor. No
(loudness) If the user gives Scratch permission to use their microphone, returns the loudness the user's microphone is receiving. Otherwise, returns -1. Yes
(timer) Returns the time (in seconds) since either the project has been loaded or the green flag has been clicked. Yes
reset timer Resets the timer to zero. Yes
((thing v) of (thing v)) Returns normally private properties of either the Stage or the given sprite. Yes
(current [thing v]) Returns the current thing. thing is one of "year", "month", "date" (day of the month), "day of week", "hour", "minute", or "second". Yes
(days since 2000) Self-explanatory. Also returns fractional portions of a day. Yes
<online?> Returns whether the user is using Scratch online or offline. Yes
(username) Returns the user's Scratch username. If they are not logged in, this returns the empty string. Yes

Operators

The Operators category contains blocks that perform operations on values. Currently, there are 18 blocks in this category.

Block Description
((a) + (b)) Numeric addition.
((a) - (b)) Numeric subtraction.
((a) * (b)) Numeric multiplication.
((a) / (b)) Numeric division. Division by zero returns infinity, and zero divided by zero returns NaN.
(pick random (a) to (b)) Chooses a random number between a and b. If either a or b is a direct numeric literal and the numeric literal has a decimal point, then the decimals will be randomized too.
((a) > (b)) Self-explanatory.
((a) < (b)) Self-explanatory.
((a) = (b)) Self-explanatory.
<<a> and > Boolean AND.
<<a> or > Boolean OR.
<not <a>> Boolean NOT.
(join (a) (b)) Joins a and b.
(letter (index) of (string)) Gets the indexth character of string, starting at one.
(length of (string)) Returns the length of string in characters.
<(a) contains (b)?> Returns whether the string a contains the string b.
<(a) mod (b)> Numeric modulo. If b is zero, this returns a NaN.
(round (x)) Rounds x.
([abs v] of (x))

([floor v] of (x))
([ceiling v] of (x))
([sqrt v] of (x))
([sin v] of (x))
([cos v] of (x))
([tan v] of (x))
([asin v] of (x))
([acos v] of (x))
([atan v] of (x))
([ln v] of (x))
([log v] of (x))
([e ^ v] of (x))
([10 ^ v] of (x))

Self-explanatory.

Variables

The Variables category contains blocks that work with variables and lists.

Block Description
set [variable v] to (value) Sets the variable variable to value.
change [variable v] by (value) Changes the variable variable by value.
show variable [variable v] Shows the variable reporter for variable on the stage.
hide variable [variable v] Hides the variable reporter for variable on the stage.
add [thing] to [list v] Appends thing to list.
delete (index) of [list v] Deletes the item of list at index index.
delete all of [list v] Self-explanatory.
insert [thing] at (index) of [list v] Self-explanatory.
replace item (index) of [list v] with (value) Self-explanatory.
(item (index) of [list v]) Retrieves the indexth item of list. Returns the empty string if index is out of bounds.
(item # of (thing) in [list v]) If thing is in list, then returns the index of the first occurrence of thing, otherwise zero.
(length of [list v]) Self-explanatory.
<[list v] contains (thing)?> Self-explanatory.
show [list v] Shows the reporter for list on the stage.
hide [list v] Hides the reporter for list.

Technically, there is another category, Lists, since Scratch considers variables and lists to be completely separate things unlike other languages such as Ruby and C++ where lists are first-class values that can be stored into variables and other lists.

My Blocks

My Blocks is a category containing custom blocks defined by the user. They can be thought of as procedures in more "traditional" languages like COBOL. In a new project, there are no custom blocks and so there is nothing in this category until the user makes a new custom block in a sprite. Custom blocks are also sprite-specific, so if you wish to have the same custom block in multiple sprites, the only way to do that is to copy the custom blocks to the sprites you want to use them in.

Upon creating a new block, a definition for it will be inserted in the current sprite and the block to invoke it will appear in the My Blocks section. When creating a custom block, labels and parameters (numeric/string or Boolean) may also be added. Additionally, custom blocks can be specified to "Run without screen refresh". Custom blocks marked with "Run without screen refresh" will make blocks that normally wait for the next frame not wait for the next frame. However, putting a block that waits more than a frame such as wait () seconds or play sound ( v) until done will cause the project to severely lag, and in some cases crash.

Extensions

Scratch also supports 12 built-in extensions that are disabled by default but can be enabled via the "Extensions" tab below the block category list.

Music

The Music extension enables projects to play musical instruments and make music much easier. Currently, this extension has 7 blocks.

Block Description
๐ŸŽถ play drum (drum v) for (duration) beats Plays the drum drum sound for duration beats. Hangs the current script until the drum has finished. drum is of the format "(Drum Number) Drum Name)", so for example Snare Drum would be "(1) Snare Drum". See the list of drums below.
๐ŸŽถ rest for (duration) beats Hangs the current script for duration beats.
๐ŸŽถ play note (note) for (duration) beats Plays the MIDI note note for duration beats with the current instrument. Hangs the current script until the note is finished.
๐ŸŽถ set instrument to (instrument v) Sets the current instrument to instrument, which is of the format "(Instrument Number) Instrument Name", so Piano would be "(1) Piano". See the list of instruments below.
๐ŸŽถ set tempo to (value) Sets the tempo to value.
๐ŸŽถ change tempo by (value) Changes the tempo by value.
(๐ŸŽถ tempo) A built-in variable shared by all sprites and the Stage that stores the tempo in beats per minute. By default, this is 60.

Drums

This is a complete list of drums that the ๐ŸŽถ play drum ( v) for () beats block uses. Currently, there are 18 drums.

  1. Snare Drum
  2. Bass Drum
  3. Side Stick
  4. Crash Cymbal
  5. Open Hi-Hat
  6. Closed Hi-Hat
  7. Tambourine
  8. Hand Clap
  9. Claves
  10. Wood Block
  11. Cowbell
  12. Triangle
  13. Bongo
  14. Conga
  15. Cabasa
  16. Guiro
  17. Vibraslap
  18. Cuica

Instruments

This is a complete list of the instruments that the Music extension uses. Currently, there are 21 instruments.

  1. Piano
  2. Electric Piano
  3. Organ
  4. Guitar
  5. Electric Guitar
  6. Bass
  7. Pizzicato
  8. Cello
  9. Trombone
  10. Clarinet
  11. Saxophone
  12. Flute
  13. Wooden Flute
  14. Bassoon
  15. Choir
  16. Vibraphone
  17. Music Box
  18. Steel Drum
  19. Marimba
  20. Synth Lead
  21. Synth Pad

Pen

The Pen extension is used to draw arbitrary shapes and images to the Stage. Anything drawn by the Pen extension draws behind all sprites, but in front of the Stage. Since the Stage itself is stationary, only the ๐Ÿ–‹๏ธ erase all block can be used there. Currently, this extension has 9 blocks.

Block Description
๐Ÿ–‹๏ธ erase all Erases everything drawn by the Pen extension.
๐Ÿ–‹๏ธ stamp "Stamps" this sprite onto the Pen canvas, or in other words draws a copy of the sprite's current costume onto the Pen canvas.
๐Ÿ–‹๏ธ pen down Brings the "pen" of this sprite down. This means that the pen starts drawing, and any change in position will result in a line being drawn from the previous position to the next.
๐Ÿ–‹๏ธ pen up Brings the "pen" of this sprite up.
๐Ÿ–‹๏ธ set pen color to (color) Sets the pen color used by ๐Ÿ–‹๏ธ pen down to color.
๐Ÿ–‹๏ธ change pen (color v) by (amount)

๐Ÿ–‹๏ธ change pen (saturation v) by (amount)
๐Ÿ–‹๏ธ change pen (brightness v) by (amount)
๐Ÿ–‹๏ธ change pen (transparency v) by (amount)

Respectively changes the color, saturation, brightness, and transparency of the pen used by ๐Ÿ–‹๏ธ pen down by amount.
๐Ÿ–‹๏ธ set pen (color v) to (amount)

๐Ÿ–‹๏ธ set pen (saturation v) to (amount)
๐Ÿ–‹๏ธ set pen (brightness v) to (amount)
๐Ÿ–‹๏ธ set pen (transparency v) to (amount)

Respectively sets the color, saturation, brightness, and transparency of the pen used by ๐Ÿ–‹๏ธ pen down to amount.
๐Ÿ–‹๏ธ change pen size by (amount) Changes the pen size used by ๐Ÿ–‹๏ธ pen down by amount with respect to pen size fencing.
๐Ÿ–‹๏ธ set pen size to (amount) Sets the pen size used by ๐Ÿ–‹๏ธ pen down to amount with respect to pen size fencing.

Video Sensing

The Video Sensing extension allows the project to sense the camera feed. Currently, this extension has 4 blocks.

Block Description
๐ŸŽฅ when video motion > (amount) Hat block that runs whenever the video motion is greater than amount.
(๐ŸŽฅ video (motion v) on (sprite v))

(๐ŸŽฅ video (direction v) on (sprite v))
(๐ŸŽฅ video (motion v) on (stage v))
(๐ŸŽฅ video (direction v) on (stage v))

Returns the either the video motion or direction on either this sprite or the Stage. If the user denies permission to their camera, returns -1.
๐ŸŽฅ turn video (on v)

๐ŸŽฅ turn video (on flipped v)
๐ŸŽฅ turn video (off v)

Turns the video feed either on or off. on flipped uses the video feed flipped horizontally.
๐ŸŽฅ set video transparency to (amount) Sets the transparency of the video feed drawn on the Stage to amount.

Face Sensing

The Face Sensing extension allows the project to sense the user's face through the camera.

Block Description
๐Ÿ™‚ go to [part of face v]
Self-explanatory. See the list below this table.
๐Ÿ™‚ point in direction of face tilt Self-explanatory.
๐Ÿ™‚ set size to face size Self-explanatory.
๐Ÿ™‚ when face tilts [left v]

๐Ÿ™‚ when face tilts [right v]

Self-explanatory hat block that runs its script whenever the face tilts either left or right.
๐Ÿ™‚ when this sprite touches a [part of face v] Self-explanatory. See the list below this table.
๐Ÿ™‚ when a face is detected Self-explanatory hat block that runs its script whenever a face is detected.
<๐Ÿ™‚ a face is detected?> Self-explanatory. If the user does not allow Scratch to use their camera, this always returns false.
๐Ÿ™‚ face tilt Returns the face tilt in degrees. If the user does not allow Scratch to use their camera, this returns 90.
๐Ÿ™‚ face size Returns the size of the detected face. If the user does not allow Scratch to use their camera, this returns 100.

This is a list of the parts of a face that Face Sensing supports.

  • nose
  • mouth
  • left eye
  • right eye
  • between eyes
  • left ear
  • right ear
  • top of head

Text to Speech

The Text to Speech extension provides TTS (text-to-speech) services for Scratch via the network. This extension currently has 3 blocks.

Block Description
๐Ÿ“ข speak [text] Speaks text using this sprite's current TTS voice and language.
๐Ÿ“ข set voice to (voice v) Sets this sprite's TTS voice to voice. The options are alto, tenor, squeak, giant, and kitten.
๐Ÿ“ข set language to (language v) Sets this sprite's TTS language to language. The languages available are Arabic, Chinese (Mandarin), Danish, Dutch, English, French, German, Hindi, Icelandic, Italian, Japanese, Korean, Norwegian, Polish, Portuguese (Brazilian), Portuguese, Romanian, Russian, Spanish, Spanish (Latin American), Swedish, Turkish, and Welsh.

Translate

The Translate extension allows translating text on the fly using the network. Currently, this extension has 2 blocks.

Block Description
(๐Ÿ’ฌ translate [text] to (language v)) Self-explanatory. See the list of languages below.
(๐Ÿ’ฌ language) Returns the of the user's set language.

This is a complete list of the languages that the Translate extension supports.

  • Amharic
  • Arabic
  • Azerbaijani
  • Basque
  • Bulgarian
  • Catalan
  • Chinese (Simplified)
  • Chinese (Traditional)
  • Croatian
  • Czech
  • Danish
  • Dutch
  • English
  • Estonian
  • Finnish
  • French
  • Galician
  • German
  • Greek
  • Hebrew
  • Hungarian
  • Icelandic
  • Indonesian
  • Irish Gaelic
  • Italian
  • Japanese
  • Korean
  • Kurdish (Sorani)
  • Latvian
  • Lithuanian
  • Maori
  • Norwegian
  • Persian
  • Polish
  • Portuguese
  • Romanian
  • Russian
  • Scots Gaelic
  • Serbian
  • Slovak
  • Slovenian
  • Spanish
  • Swedish
  • Thai
  • Turkish
  • Ukranian
  • Vietnamese
  • Welsh
  • Zulu

Makey Makey

This extension has two blocks.

Block Description
๐ŸŽฎ when (key v) key pressed Self-explanatory hat block that runs its script whenever the key key is pressed. Unlike the when [key v] key pressed block from the Events category, up and down arrow are not triggered by mouse scrolling.
๐ŸŽฎ when (sequence v) pressed in order Self-explanatory hat block that runs its script when the sequence sequence of keys is pressed in order. The list of key sequences can be found below this table.

This is the list of key sequences for the ๐ŸŽฎ when ( v) pressed in order hat block.

  • left right up
  • right up left
  • left right
  • up down
  • down up
  • up right down left
  • up left down right
  • up up down down left right left right

micro:bit

The micro:bit extension provides blocks for Scratch to be able to interact with the micro:bit. Currently, there are 10 blocks in this extension.

Block Description
โŒจ๏ธ when (button v) button pressed Hat block that runs its script when the given button of the micro:bit is pressed. button is one of "A", "B", or "any".
<โŒจ๏ธ (button v) button pressed?> A block that returns whether the given button of the micro:bit is pressed. button is one of "A", "B", or "any".
โŒจ๏ธ when (action v) Hat block that runs its script when the given action is performed with the micro:bit. action is one of "moved", "shaken", or "jumped".
โŒจ๏ธ display (pattern v) Displays pattern on the micro:bit. pattern is a 5x5 grid of either on or off.
โŒจ๏ธ display text [text] Self-explanatory.
โŒจ๏ธ clear display Self-explanatory.
โŒจ๏ธ when tilted (direction v) Hat block that runs its script when the micro:bit is tilted in the direction direction. See the list of tilt directions below this table.
<โŒจ๏ธ tilted (direction v)?> Returns whether the micro:bit is being tilted in the direction direction. See the list of tilt directions below this table.
(โŒจ๏ธ tilt angle (direction v)) Returns the tilt angle of the micro:bit in the direction direction. direction can be any of the tilt directions listed below this table, except for any.
โŒจ๏ธ when pin (pin # v) connected Hat block that runs its script when the pin pin # is connected. pin # can be 0, 1, or 2.

Go Direct Force & Acceleration

The Go Direct Force & Acceleration extension provides blocks that interact with the Vernier Go Direct Force and Acceleration sensor.[2] Currently, there are 9 blocks in this category.

Block Description
๐Ÿ“ฑ when (action v) Hat block that runs its script when action is performed on the force sensor. action is one of "shaken", "started falling", "turned face up", and "turned face down".
๐Ÿ“ฑ when force sensor (action v) Hat block that runs its script when action is performed on the force sensor. action is either "pushed" or "pulled".
(๐Ÿ“ฑ force) Returns the force of the push or pull on the force sensor.
๐Ÿ“ฑ when tilted (direction v) Hat block that runs its script when the force sensor is tilted in the given direction. The list of directions is the same as that of the micro:bit.
<๐Ÿ“ฑ tilted (direction v)?> Returns whether the force sensor is tilted in the given direction. The list of directions is the same as that of the micro:bit.
(๐Ÿ“ฑ tilt angle (direction v)) Returns the force sensor's tilt angle in the given direction, where direction can be any direction from the list of directions except any. The list of directions is the same as that of the micro:bit.
<๐Ÿ“ฑ falling?> Returns whether the force sensor is falling.
(๐Ÿ“ฑ spin speed (axis v)) Returns the force sensor's spin speed on the given axis, which can be "x", "y", or "z".
(๐Ÿ“ฑ acceleration (axis v)) Returns the force sensor's acceleration on the given axis, which can be "x", "y", or "z".

LEGO MINDSTORMS EV3

This section is a stub. Please help us by adding more information.

The LEGO MINDSTORMS EV3 extension provides blocks that allow programming the EV3 with Scratch.[3]

Block Description
๐Ÿ–ฅ๏ธ motor (motor v) turn this way for (duration) seconds Turns[what direction?] the motor motor (A, B, C, or D) for duration seconds and hangs the script until it is done.
๐Ÿ–ฅ๏ธ motor (motor v) turn that way for (duration) seconds Turns[what direction?] the motor motor (A, B, C, or D) for duration seconds and hangs the script until it is done.
๐Ÿ–ฅ๏ธ motor (motor v) set power (amount) % Sets the power of the motor motor (A, B, C, or D) to amount percent.
(๐Ÿ–ฅ๏ธ motor (motor v) position) Returns the position[exact meaning?] of the given motor. motor is one of A, B, C, or D.
๐Ÿ–ฅ๏ธ when button (button v) pressed Hat block that runs its script whenever button (one of 1, 2, 3, or 4) is pressed.
๐Ÿ–ฅ๏ธ when distance < (amount) Hat block that runs its script when the distance[what distance?] is less than amount.
<๐Ÿ–ฅ๏ธ button (button v) pressed?> Returns whether the given button (one of 1, 2, 3, or 4) is pressed.
(๐Ÿ–ฅ๏ธ distance) Returns the distance.[what distance?]
(๐Ÿ–ฅ๏ธ brightness) Returns the brightness.[what brightness?]
๐Ÿ–ฅ๏ธ beep note (note) for (duration) secs Beeps the MIDI note note for duration seconds and hangs the script until it is done.

LEGO BOOST

This section is a stub. Please help us by adding more information.

LEGO Education WeDo 2.0

This section is a stub. Please help us by adding more information.

Examples

These are all written in Scratch 3.0.

Hello, world! program

when flag clicked
say [Hello, world!]

See as an image here.

Looping counter

when flag clicked
set [my variable v] to (0)
forever
  say (my variable) for (1) seconds
  change [my variable v] by (1)
end

See as an image here.

Truth-machine

If the input is zero, meows once. Otherwise, meows forever.

when flag clicked
ask [input?] and wait
repeat until <(answer) = (0)>
  play sound [Meow v] until done
end
play sound [Meow v] until done

See as an image here.

99 bottles of beer

The output is stored in a list named "output".

when flag clicked
set [bottles v] to (99)
delete all of [output v]
repeat until <(bottles) = (2)>
  add (join (bottles) [ bottles of beer on the wall,]) to [output v]
  add (join (bottles) [ bottles of beer.]) to [output v]
  add [Take one down, pass it around,] to [output v]
  change [bottles v] by (-1)
  add (join (bottles) [ bottles of beer on the wall.]) to [output v]
  add [] to [output v]
end
add [2 bottles of beer on the wall,] to [output v]
add [2 bottles of beer.] to [output v]
add [Take one down, pass it around,] to [output v]
add [1 bottle of beer on the wall.] to [output v]
add [] to [output v]
add [1 bottle of beer on the wall,] to [output v]
add [1 bottle of beer.] to [output v]
add [Take one down, pass it around,] to [output v]
add [No more bottles of beer on the wall.] to [output v]
add [] to [output v]
add [No more bottles of beer on the wall,] to [output v]
add [No more bottles of beer.] to [output v]
add [Go to the store, buy some more,] to [output v]
add [99 bottles of beer on the wall.] to [output v]

See as an image here.

Bitwise Cyclic Tag

define BCT (init program) (init data)
set [program v] to (init program)
set [data v] to (init data)
set [ip v] to (0)
if <(length of (program)) = (0)> then
  stop [this script v]
end
repeat until <(length of (data)) = (0)>
  if <(letter ((1) + (ip)) of (program)) = (0)> then
    set [tmp v] to ()
    set [tmp2 v] to (2)
    repeat until <(tmp2) > (length of (data))>
      set [tmp v] to (join (tmp) (letter (tmp2) of (data))
      change [tmp2 v] by (1)
    end
    set [data v] to (tmp)
    set [ip v] to (((ip) + (1)) mod (length of (program)))
  else
    set [ip v] to (((ip) + (1)) mod (length of (program)))
    if <(letter (1) of (data)) = (1)> then
      set [data v] to (join (data) (letter ((ip) + (1)) of (program)))
    end
    set [ip v] to (((ip) + (1)) mod (length of (program)))
  end
end

See as an image here.

Alternatively, search here.

See Also

References

External resources