Block Plugin - Scratch Wiki (original) (raw)

SandCastleIcon.png This article has links to websites or programs outside of Scratch and Wikipedia. Remember to stay safe while using the internet, as we cannot guarantee the safety of other websites.

The Block Plugin, also known as scratchblocks4, is a plugin for the Scratch Wiki and Forums maintained by the user blob8108 that allows script images to be constructed through text that is parsed and rendered. The plugin itself can be played around with on its homepage[1]. For example:

define dance (speed) set [dist v] to ((speed) * (distance to (mouse-pointer v))) repeat until <(timer) > [10]> move (dist) steps next costume play note (pick random (40) to (100)) for (0.5) beats say [Wow! Scratch scripts on the Wiki!] end

Basic Syntax

Main article: Block Plugin/Syntax

On the Scratch Wiki, block code must be inserted between the <scratchblocks>...</scratchblocks> tags, while on the forums, they are inserted between [scratchblocks]...[/scratchblocks] tags. On the Scratch Wiki, uniquely, a single block can also be inserted inline between <sb>...</sb> tags to avoid breaking lines.

The block plugin tries to match the code you write as close as possible and does not check you've used the correct syntax. The block text is only used to find the correct color.

The basic syntax of the Block Plugin is as follows:

Code Use Example Result
block name a block erase all erase all
end stops a C block (only necessary if more blocks come after the C block) repeat (5) move (10) steps end say [Done!] repeat (5) move (10) steps end say [Done!]
[text] a text input say [Hello World!] say [Hello World!]
(var) a variable or reporter block (x position) (x position)
(12.34) a number input wait (0.5) seconds wait (0.5) seconds
(item v) an insertable dropdown input broadcast (You Win v) broadcast (You Win v)
[item v] an uninsertable dropdown input set [my variable v] to (0) set [my variable v] to (0)
a boolean block <mouse down?> <mouse down?>
[#ABCDEF] a color input <touching color [#0000FF]?> <touching color [#0000FF]?>
define a custom block hat define jump (height) define jump (height)
// comment a comment show // now you see me show // now you see me
... a placeholder block denoting an arbitrary script if <(var) = [this]> then ... end if <(var) = [this]> then ... end

Advanced Syntax

The following is some more in-depth syntax of scratchblocks3.

Code Use Example Result
block { more blocks } optional text Custom C blocks do { ... } in the stage::control do { ... } in the stage::control
{stack block as reporter} Cause a block to have a stack block as an input. decorate {show} decorate {show}
:: [category or #color] [shape] Force a block to look a certain way. Possible category options include:motion looks sound pen variables list events control sensing operators custom custom-arg extension grey[note 1] obsolete The other way you can set color is by setting it through an extension shape. Note that these do not work with any other colors - it is always extension colored. Possible extension colors include: music pen video tts OR text2speech translate wedo OR wedo2 ev3 microbit makeymakey gdxfor boost #colors can be any hexadecimal RGB color, for example #ff0000 which produces a pure red.Possible shapes include: hat stack ring boolean reporter cap cat a cool block:: #ff00ff cap a cool block:: #ff00ff cap
::ring Replicate Snap_!'_s "ringify" feature. This can be used in conjunction with the above colon syntax as well. It looks like a reporter, but it has a difference. Look,({It's in a ring!}@addInput::ring Look,({It's in a ring!}@addInput::ring
-block Put a hyphen (-) before a block to show a horizontal line through the block, as if it is crossed out. -say [This is striked-through!] for (2) seconds -say [This is striked-through!] for (2) seconds
+block Put a plus (+) before a block outline or select the block. +say [This is selected!] for (2) seconds +say [This is selected!] for (2) seconds
canceling the next character [[example\] Putting a backslash before a special character will cancel it, so you don't close a text input earlier than intended. This allows you to put 'close brackets' inside of a text input. say [[example\]] say [[example\]]
@greenFlag Add a green flag to the code in a block it's not usually in. <@greenFlag pressed?::events> <@greenFlag pressed?::events>
@stopSign Add a stop sign to the code in a block it's not usually in. <@stopSign pressed?::events> <@stopSign pressed?::events>
@delInput@addInput Replicate Snap_!'_s feature for adding and deleting inputs. create variable [foo] [bar] @delInput @addInput::variables create variable [foo] [bar] @delInput @addInput::variables
@loopArrow Add the loop arrow seen in repeat C-blocks in Scratch. if <[1]=[1]> then repeat{ . . . } @loopArrow::control if <[1]=[1]> then repeat{ . . . } @loopArrow::control
@turnLeft @turnRight Add the direction turning as seen in the "turn direction" blocks. turn @turnLeft () degrees then @turnRight () degrees::motion turn @turnLeft () degrees then @turnRight () degrees::motion
@list Add the list array symbol as seen in Snap_!_ add [] to @list[ v]::list add [] to @list[ v]::list

Block Styles

Different style blocks can be used using the 'version' attribute: Scratch 2.0 style blocks can be used by using '2.0' and 3.0 high-contrast blocks using 'hc-3'. Examples of both are below.

when gf clicked repeat (10) // comment in 2.0 move (5) steps end say [Cool! Scratchblocks in 2.0!] stop [this script v]

when gf clicked repeat (10) // comment in high contrast move (5) steps end say [Also in high contrast!] stop [this script v]

  1. Spelled with an e, not an a.

Helper Tools

Here are some tools that will convert real blocks in Scratch projects into scratchblocks code.

Scratch 3.0

The user apple502j developed a library called parse-sb3-blocks, which reads blocks from a Scratch 3 project.json and converts them to the scratchblocks syntax. They also created a scratchblocks code generator that can read projects shared on the Scratch website, which can be used here.

Scratch 2.0

The user jvvg developed a converter written in PHP that converts scripts in the backpack. The forum thread for this converter can be viewed here.

Scratch 1.4

The user LS97 developed a plugin for the Scratch program itself that converts a script into scratchblocks (the original) code. The forum thread for the plugin can be viewed here.

See Also

Official scratchblocks homepage

References

  1. http://scratchblocks.github.io/#?style=scratch3&script=

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

The Wiki is working on a dark theme, and you're seeing it! Got feedback? Post on the Wiki Forum Topic.