(For Scratch 2.0: generator has moved also)
(Undo revision 256312 by Col Cat228 (talk) Changing the block shape is already mentioned later in the page)
 
(84 intermediate revisions by 31 users not shown)
Line 1: Line 1:
The '''Block Plugin''', also known as '''scratchblocks2''', is a plugin for the [[Scratch Wiki]] and [[Scratch Forums|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 [http://scratchblocks.github.io/ on the test page].
+
{{External Programs}}
 
+
The '''[[Block]] Plugin''', also known as '''scratchblocks4''', is a plugin for the [[Scratch Wiki]] and [[Scratch Discussion Forums|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.
It is a complete rewrite of the [[Block Plugin (1.4)|old plugin by JSO]] that was used on the [[Scratch Forums (1.4)|old Scratch forums]].
 
 
 
 
Example:
 
Example:
 
<scratchblocks>
 
<scratchblocks>
Line 9: Line 7:
 
repeat until <(timer) > [10]>
 
repeat until <(timer) > [10]>
 
   move (dist) steps
 
   move (dist) steps
   play note (42 v) for (0.5) beats
+
  next costume
   say [Wow! Scratch 2.0 scripts on the Wiki!]
+
   play note (pick random (40) to (100)) for (0.5) beats
 +
   say [Wow! Scratch scripts on the Wiki!]
 
end
 
end
 
</scratchblocks>
 
</scratchblocks>
  
==Basic Syntax==
+
== Basic Syntax ==
 
 
 
{{main|Block Plugin/Syntax}}
 
{{main|Block Plugin/Syntax}}
 +
On the Scratch Wiki, block code must be inserted between the <code><nowiki><scratchblocks>...</scratchblocks></nowiki></code> tags, while on the forums, they are inserted between <code>[scratchblocks]...[/scratchblocks]</code> tags. On the Scratch Wiki, uniquely, a single block can also be inserted inline between <code><nowiki><sb>...</sb></nowiki></code> tags to avoid breaking lines.
  
On the Scratch Wiki, code must be inserted between the <code><nowiki><scratchblocks>...</scratchblocks></nowiki></code> tags, while on the forums they are inserted between <code>[scratchblocks]...[/scratchblocks]</code> 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 color.
 
 
The [[Blocks|block]] plugin tries to match the code you write as closely as possible, and doesn't 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:
 
The basic syntax of for the Block Plugin is as follows:
{| class="wikitable"
+
{| class="wikitable" width="100%"
 
|-
 
|-
 
! Code
 
! Code
 
! Use
 
! Use
 
! Example
 
! Example
! width="150px;" | Which renders
+
! Result
 
|-
 
|-
| <code>block name</code>
+
| <pre style="display:table">block name</pre>
 
| a block
 
| a block
| <code>stamp</code>
+
| <pre style="display:table">erase all</pre>
| <scratchblocks>stamp</scratchblocks>
+
| <scratchblocks>erase all</scratchblocks>
 
|-
 
|-
| <code>end</code>
+
| <pre style="display:table">end</pre>
| stops a [[C Block|C block]] (only necessary in the middle of a script)
+
| stops a [[C Block|C block]] (only necessary if more blocks come after the C block)
| <pre>repeat (5)
+
| <pre style="display:table">repeat (5)
move (10) steps
+
  move (10) steps
 
 
 
end
 
end
 
say [Done!]</pre>
 
say [Done!]</pre>
 
| <scratchblocks>
 
| <scratchblocks>
 
repeat (5)
 
repeat (5)
move (10) steps
+
  move (10) steps
 
end
 
end
say [Done!]</scratchblocks>
+
say [Done!]
 +
</scratchblocks>
 
|-
 
|-
| <code>[text]</code>
+
| <pre style="display:table">[text]</pre>
 
| a text input
 
| a text input
| <code>say [Hello World]</code>
+
| <pre style="display:table">say [Hello World!]</pre>
| <scratchblocks>say [Hello World]</scratchblocks>
+
| <scratchblocks>say [Hello World!]</scratchblocks>
 
|-
 
|-
| <code>(variable)</code>
+
| <pre style="display:table">(var)</pre>
| a [[variable]] or [[Reporter Block]]
+
| a variable or [[Reporter Block|reporter block]]
| <code>(x position)</code>
+
| <pre style="display:table">(x position)</pre>
 
| <scratchblocks>(x position)</scratchblocks>
 
| <scratchblocks>(x position)</scratchblocks>
 
|-
 
|-
| <code>(123.4)</code>
+
| <pre style="display:table">(12.34)</pre>
 
| a number input
 
| a number input
| <code>wait (0.5) secs</code>
+
| <pre style="display:table">wait (0.5) seconds</pre>
| <scratchblocks>wait (0.5) secs</scratchblocks>
+
| <scratchblocks>wait (0.5) seconds</scratchblocks>
 
|-
 
|-
| <code>[text v]</code>
+
| <pre style="display:table">[item v]</pre>
| a dropdown box
+
| a dropdown input
| <code>broadcast [Start v]</code>
+
| <pre style="display:table">broadcast [You Win v]</pre>
| <scratchblocks>broadcast [Start v]</scratchblocks>
+
| <scratchblocks>broadcast [You Win v]</scratchblocks>
 
|-
 
|-
| <code><boolean></code>
+
| <pre style="display:table"><bool></pre>
| a [[Boolean Block]]
+
| a [[Boolean Block|boolean block]]
| <code><mouse down?></code>
+
| <pre style="display:table"><mouse down?></pre>
 
| <scratchblocks><mouse down?></scratchblocks>
 
| <scratchblocks><mouse down?></scratchblocks>
 
|-
 
|-
| <code>[#FFFFFF]</code>
+
| <pre style="display:table">[#ABCDEF]</pre>
 
| a color input
 
| a color input
| <code><touching color [#FF0000]?></code>
+
| <pre style="display:table"><touching color [#0000FF]?></pre>
| <scratchblocks><touching color [#FF0000]?></scratchblocks>
+
| <scratchblocks><touching color [#0000FF]?></scratchblocks>
 
|-
 
|-
| <code>define</code>
+
| <pre style="display:table">define</pre>
| a [[Define ()|Custom Block]] hat
+
| a [[Custom Block|custom block]] hat
| <code>define jump (height)</code>
+
| <pre style="display:table">define jump (height)</pre>
 
| <scratchblocks>define jump (height)</scratchblocks>
 
| <scratchblocks>define jump (height)</scratchblocks>
 
|-
 
|-
| <code>// text</code>
+
| <pre style="display:table">// comment</pre>
| a [[Comments|comment]]
+
| a [[Comment (programming feature)|comment]]
| <code>show // Appear!</code>
+
| <pre style="display:table">show // now you see me</pre>
| <scratchblocks>show // Appear!</scratchblocks>
+
| <scratchblocks>show // now you see me</scratchblocks>
 
|-
 
|-
| <code>. . .</code>
+
| <pre style="display:table">...</pre>
| a placeholder for unspecified, optional scripts
+
| a placeholder block denoting an arbitrary script
| <code>repeat until <touching [sprite 1 v]?>
+
| <pre style="display:table">if <(var) = [this]> then
. . .</code>
+
  ...
 +
end</pre>
 
| <scratchblocks>
 
| <scratchblocks>
repeat until <touching [sprite 1 v]?>
+
if <(var) = [this]> then
. . .</scratchblocks>
+
  ...
 +
end
 +
</scratchblocks>
 +
|}
 +
 
 +
== Advanced Syntax ==
 +
The following is some more in-depth syntax of scratchblocks3.
 +
{| class="wikitable" width="100%"
 
|-
 
|-
| <code>:: shape/category</code>
+
! Code
| forces a block to appear as a specific category, or as a specific shape.
+
! Use
| <code>custom block :: looks stack</code>
+
! Example
| <scratchblocks>custom block // category=looks</scratchblocks>
+
! Result
 +
|-
 +
| <pre style="display:table">block {
 +
  more blocks
 +
} optional text</pre>
 +
| Custom C blocks
 +
| <pre style="display:table">do {
 +
  ...
 +
} in [Sprite2 v]::control</pre>
 +
| <scratchblocks>
 +
do {
 +
  ...
 +
} in [Sprite2 v]::control
 +
</scratchblocks>
 +
|-
 +
| <pre style="display:table">(stack block as reporter::stack)</pre>
 +
| Cause a block to have a stack block as an input.
 +
| <pre style="display:table">decorate (show::stack)</pre>
 +
| <scratchblocks>decorate (show::stack)</scratchblocks>
 +
|-
 +
| <pre style="display:table">:: [category or #colour] [shape]</pre>
 +
| Force a block to look a certain way. Possible <code>category</code> options include:
 +
* motion
 +
* looks
 +
* sound
 +
* pen
 +
* variables
 +
* list
 +
* events
 +
* control
 +
* sensing
 +
* operators
 +
* custom
 +
* custom-arg
 +
* extension
 +
* grey<ref group="note">Spelled with an e, not an a.</ref>
 +
* undefined
 +
<code>#colour</code>s can be any hexadecimal RGB color, for example <code>#ff0000</code> which produces a <font color="#ff0000">pure red</font>.
 +
 
 +
Possible <code>shape</code>s include:
 +
* hat
 +
* stack
 +
* cap
 +
* cat (Scratch Wiki only)
 +
| <pre style="display:table">a cool block:: #ff00ff cap</pre>
 +
| <scratchblocks>a cool block:: #ff00ff cap</scratchblocks>
 +
|-
 +
| <pre style="display:table">::ring</pre>
 +
| Replicate [[Snap]]'s "ringify" feature. This can be used in conjunction with the above colon syntax as well.
 +
| <pre style="display:table">block::ring</pre>
 +
| <scratchblocks>block::ring</scratchblocks>
 
|}
 
|}
{{Note}}The block plugin makes booleans look like reporter blocks.
+
<references group="note" />
 +
 
 +
== Helper Tools ==
 +
Here are some tools that will convert real blocks in Scratch [[project]]s into scratchblocks code.
 +
 
 +
=== Scratch 3.0 ===
 +
The user blob8108 developed [[Scratch 2.0]]'s blocks, which now also supports [[Scratch 3.0]] blocks.<ref>http://scratchblocks.github.io/#?style=scratch3&script=</ref>He also developed a converter written in JavaScript that converts an entire project's scripts into scratchblocks. It can be found [https://scratchblocks.github.io/generator 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 [[topic:14413|here]].
  
==Helper Tools==
+
=== Scratch 1.4 ===
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 <code><nowiki><scratchblocks></nowiki></code> tag.
+
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 [[ar-topic:102175|here]].
  
===For Scratch 1.4===
+
== See Also ==
* The [[Scratcher]] LS97 developed a plugin for the Scratch program that converts a script to ScratchBlocks code. The forum thread for this plugin is [{{Forum Archive|102175}} here].
+
* The [[S:SB2STYLE|style guide]] for using the Block Plugin on the Scratch Wiki
  
===For Scratch 2.0===
+
== External Links ==
* blob8108 developed a JavaScript converter for Scratch 2.0 that will convert an entire project, and the code for that is [http://scratchblocks.github.io/generator/ here].
+
[http://scratchblocks.github.io Official scratchblocks homepage]
  
* jvvg developed a PHP version that will convert scripts in users' [[backpack]]s, and the forum thread is [http://scratch.mit.edu/discuss/topic/14413/ here].
+
== References ==
 +
<references />
  
==History==
 
{{other version|2.0|1.4}}
 
 
[[Category:Scratch Extensions]]
 
[[Category:Scratch Extensions]]
 
[[de:Scratch-Wiki:Hilfe:Block Plugin]]
 
[[de:Scratch-Wiki:Hilfe:Block Plugin]]
 +
[[fr:Blocs du forum]]
 +
[[ja:ブロックプラグイン]]

Latest revision as of 12:45, 10 August 2020

SandCastleIcon.png This page has links to websites or programs not trusted by Scratch or hosted by Wikipedia. Remember to stay safe while using the internet, as we can't 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. 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 closely 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 for 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]
a dropdown input
broadcast [You Win v]
broadcast [You Win v]
<bool>
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 [Sprite2 v]::control
do {
  ...
} in [Sprite2 v]::control
(stack block as reporter::stack)
Cause a block to have a stack block as an input.
decorate (show::stack)
decorate (show::stack)
:: [category or #colour] [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]
  • undefined

#colours can be any hexadecimal RGB color, for example #ff0000 which produces a pure red.

Possible shapes include:

  • hat
  • stack
  • cap
  • cat (Scratch Wiki only)
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.
block::ring
block::ring
  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 blob8108 developed Scratch 2.0's blocks, which now also supports Scratch 3.0 blocks.[1]He also developed a converter written in JavaScript that converts an entire project's scripts into scratchblocks. It can be found 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

  • The style guide for using the Block Plugin on the Scratch Wiki

External Links

Official scratchblocks homepage

References

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