In other languages

Help the wiki!

The Scratch Wiki is made by and for Scratchers. Do you want to contribute?

Learn more about joining as an editor!

See discussions in the Community Portal

Block Plugin

SandCastleIcon.png This page has links to outside of the Scratch website or to Wikipedia. Always remember to be safe when using the internet since we can't guarantee the safety of other sites.

The Block Plugin, also known as scratchblocks2, is a plugin for the Scratch Wiki and Scratch forums created by blob8108 that allows script images to be constructed through text that is parsed and rendered. You can try playing around with the plugin on the test page.

It is a complete rewrite of the old plugin by JSO that was used on the old Scratch forums.

Example:

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

Basic Syntax

Main article: Block Plugin/Syntax

On the Scratch Wiki, code must be inserted between the <scratchblocks>...</scratchblocks> tags, while on the forums they are inserted between [scratchblocks]...[/scratchblocks] tags.

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

The basic syntax of for the Block Plugin is as follows:

Code Use Example Which renders
block name a block stamp
stamp
end stops a C block (only necessary in the middle of a script)
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]
(variable) a variable or Reporter Block (x position)
(x position)
(123.4) a number input wait (0.5) secs
wait (0.5) secs
[text v] a dropdown box broadcast [Start v]
broadcast [Start v]
<boolean> a Boolean Block <mouse down?>
<mouse down?>
[#FFFFFF] a color input <touching color [#FF0000]?>
<touching color [#FF0000]?>
define a Custom Block hat define jump (height)
define jump (height)
// text a comment show // Appear!
show // Appear!
. . . a placeholder for unspecified, optional scripts repeat until <touching [sprite 1 v]?>

. . .

repeat until <touching [sprite 1 v]?>
. . .
:: shape/category forces a block to appear as a specific category, or as a specific shape. custom block :: looks stack
custom block :: looks stack

Advanced Syntax

More in-depth documentation of the scratchblocks2 plugin is listed here:

Markup Usage Possible syntax
{stack} Code placed inside curly brackets is encapsulated in its own stack block. Modifiers must be included inside the brackets in order to remain valid.
(reporter) Code placed inside parenthesis is encapsulated in its own reporter block. Modifiers must be included inside the parenthesis in order to remain valid.
<boolean> Code placed inside inequality symbols is encapsulated in its own boolean block. Modifiers must be included inside the inequality symbols in order to remain valid.
::(color) Forces target block to inherit color of the keyword's respective category. Colons are placed at the end of any block. Possible inputs that can be placed after the two colons:
  • motion
  • looks
  • sound
  • pen
  • variables
  • list
  • events
  • control
  • sensing
  • operators
  • custom
  • custom-arg
  • extension
  • grey
  • undefined
::(type) Forces target block to inherit shape of the keyword's respective category. Colons are placed at the end of any block. Possible inputs that can be placed after the two colons:
  • hat
  • stack
  • cstart
  • celse
  • cend
  • cap
::ring Replicates Snap's "ringify" feature. This modifier can be appended to the end of a block to "ringify" its target block. It can be used in conjunction with other "colon modifiers."
//(comment) Used to replicate comments in the Scratch editor. The double slashes are a common annotation feature found in many text based languages. The comment must be placed at the very end of the line because all characters after the double slashes will be interpreted as a comment.
[text v](number v) Used to turn text and number inputs into drop-down menus. The space and letter "v" must be inserted immediately before the closing bracket/parenthesis of the text/number input.

Helper Tools

There are a few tools that you can use that will take blocks directly from a Scratch project, and turn them into text that you can paste inside a <scratchblocks> tag.

For Scratch 1.4

  • The Scratcher LS97 developed a plugin for the Scratch program that converts a script to ScratchBlocks code. The forum thread for this plugin is here.

For Scratch 2.0

  • blob8108 developed a JavaScript converter for Scratch 2.0 that will convert an entire project, and the code for that is here.
  • jvvg developed a PHP version that will convert scripts in users' backpacks, and the forum thread is here.

History

This article or section documents the current version of Scratch (version 2.0). For this article in Scratch 1.4, see Block Plugin (1.4).
  • This page was last modified on 24 July 2016, at 16:34.