(Ellipsis)
(Inline Scratchblocks)
Line 200: Line 200:
  
 
=== Inline Scratchblocks ===
 
=== Inline Scratchblocks ===
You can place scratchblocks inside a sentence using the <code><nowiki><sb2></nowiki></code> tag, like this:
+
You can place scratchblocks inside a sentence using the <code><nowiki><sb></nowiki></code> tag, like this:
:''I'm rather fond of the <sb2>stamp</sb2> block in Scratch 2.0.''
+
:<pre>I'm rather fond of the <sb>stamp</sb> block in Scratch 2.0.</pre>
 +
Producing:
 +
:I'm rather fond of the <sb>stamp</sb> block in Scratch 2.0.
  
 
Some notes:
 
Some notes:
 
* You can only use a single block in the inline tag, not a whole script. This is by design.
 
* You can only use a single block in the inline tag, not a whole script. This is by design.
 
* Use the inline tag where appropriate.
 
* Use the inline tag where appropriate.
 +
* Use it to represent variable names: <sb>(score)</sb>
 
* To make a link containing a block image, instead of using an image, use the following markup:
 
* To make a link containing a block image, instead of using an image, use the following markup:
 
:<pre>[[Stamp (block)|<sb>stamp</sb>]]</pre>
 
:<pre>[[Stamp (block)|<sb>stamp</sb>]]</pre>
 +
Producing:
 +
:[[Stamp (block)|<sb>stamp</sb>]]
  
 
=== Set Block Colour ===
 
=== Set Block Colour ===

Revision as of 11:40, 20 September 2014

Shortcut:
S:SB2STYLE

In order to keep the Scratch Wiki looking neat, please follow the following style guide when writing <scratchblocks> on the wiki.

Feel free to fix any articles that don't conform to this guide.

This guide is intended for wiki editors, and includes guidelines on style as well as a little extra syntax. It thus serves a different purpose to Block Plugin/Syntax, which is a guide to the syntax intended for both wiki editors and forum users.

Whitespace

  • Always put a line break before and after the opening and closing <scratchblocks> tags.
No:
I like this script: <scratchblocks>when flag clicked
say [Hello!]</scratchblocks> Pretty, isn't it?

Yes:

I like this script:

<scratchblocks>
when gf clicked
say [Hello!]
</scratchblocks>

  • However, if you're writing a script with a single block, only use one line:
Yes:
<scratchblocks>when gf clicked</scratchblocks>
  • Use indentation. Always indent by 4 spaces. (This is for consistency as much as for any other reason.)
No:
repeat (10)
if <touching [mouse-pointer v]?>
move (10) steps
end
stamp
end

Yes:

repeat (10)
    if <touching [mouse-pointer v]?>
        move (10) steps
    end
    stamp
end
  • Always put whitespace around inserts and embedded blocks. This is easier to read.
No Yes
if<mouse down?> then
if <mouse down?> then
<(variable)=[3]>
<(variable) = [3]>
(join (((3)*(3))+((3)/((3)-(3))))[j])
(join (((3) * (3)) + ((3) / ((3) - (3)))) [j])
set size to (100)%
set size to (100) %
Note Note: This last example is currently broken due to a mysterious wiki-only bug.
  • Always put spaces around the comment symbol "//".
No:
stamp//Draws a picture!

Yes:

stamp // Draws a picture!

Laziness

The block plugin will insert certain things for you automatically, in case you forget. Don't rely on this; always include properly formatted scripts in wiki articles. If Javascript is disabled then the source code will be displayed directly to the user, so we want the article source to be readable.

  • Always include "end" after a C block.
No:
repeat (10)
    move (10) steps
    stamp

Yes:

repeat (10)
    move (10) steps
    stamp
end
  • Always close brackets.
No:
if <<(x position) < [3]> and <(var) = [4

Yes:

if <<(x position) < [3]> and <(var) = [4]>>

Scratch 2.0 Blocks

Make sure you use the 2.0 versions of blocks (unless it's an article specifically about Scratch 1.4). This includes:

Scratch 1.4 Block Replacement
switch to costume [costume1 v] 
switch costume to [costume1 v]
switch to background [background1 v] 
switch backdrop to [background1 v]
next background
next backdrop
(background #)
(backdrop #)
if <>
if <> then
forever if <>
forever
    if <>
stop script
stop [this script v]
stop all
stop [all v]
when Sprite1 clicked
when this sprite clicked
<loud?>
<(loudness) > [30]>

The (user id) Block

"Now we have the category hack, I'm going to remove the (user id) block from the scratchblocks plugin's database, just for fun in light of my nefarious master plan to switch to generating the blocks list directly from the decompiled SWF sources Scratch 2.0 source code.

—blob8108

Summary: Replace "(user id)" with "(user id :: sensing)" where appropriate.

Note Note: I think the wiki plugin still hasn't been updated yet, so double-colon hacks may not work yet: (user id :: sensing)

New features

Ellipsis

You can now use the grey . . . ellipsis block to represent gaps in scripts.

  • If you're putting a deliberate gap in a script--use it! Don't write the word "script", "scripts", any other obsolete block, or a comment saying "script goes here".
No:
forever
    if <>
        script
    end
end

No:

forever
    if <>
        // script goes here
    end
end

Yes:

forever
    if <>
        . . .
    end
end
  • Always write . . ., with spaces between the dots. This makes the block easier to read.

Inline Scratchblocks

You can place scratchblocks inside a sentence using the <sb> tag, like this:

I'm rather fond of the <sb>stamp</sb> block in Scratch 2.0.

Producing:

I'm rather fond of the stamp block in Scratch 2.0.

Some notes:

  • You can only use a single block in the inline tag, not a whole script. This is by design.
  • Use the inline tag where appropriate.
  • Use it to represent variable names: (score)
  • To make a link containing a block image, instead of using an image, use the following markup:
[[Stamp (block)|<sb>stamp</sb>]]

Producing:

stamp

Set Block Colour

You can now set the colour of a block using a secret comment hack: // category=[...]. For example, the "create clone" block from the prototype was renamed "create clone of", so it normally appears obsolete:

create clone
create clone

But by putting a special comment, you can get the correct colour:

create clone // category=control
create clone // category=control

Warning: The syntax for this will change in the future, so use it sparingly.

External Links