Each block is described by an array with the following fields:
block type
block format
operation or remote variable name
(optional) zero or more default parameter values
The block type is one of these strings:
" " – command block
“w" – command block that waits
“r" – number reporter block (round ends) ==> 前面有帶一個 checkbox
“b" – boolean reporter block (pointy ends)
“R" – Reporters that wait (round ends)
The block format is a string that describes the labels and parameter slots that appear on the block. Parameter slots are indicated by a word starting with “%" and can be one of:
%n – number parameter (round ends)
%s – string parameter (square ends)
%b – boolean parameter (pointy ends)
Menu parameters
Both command and reporter blocks can include menu parameters:
/beep (command with no parameters) /setVolume/5 (command with a numeric parameter)
Commands that wait
turn motor on for 3 seconds
turns on the motor, waits three seconds, then turns it off again. When this block is used in a script, execution does not continue to the next block until the command completes. A command that waits is indicated by the “w" block type in the command descriptor.
When a “w" command is invoked, Scratch adds a unique command_id parameter to the request (before any other parameters). For example, for the motor command above Scratch would send:
request: /motorOn/2437/3
The first parameter, 2437, is a unique identifier for this invocation of the command. For the three seconds that this command takes to complete, the helper app adds a busy line to the poll request:
response: _busy 2437 …
A busy line consists of the string “_busy" followed by a list of unique identifiers separated by spaces. When Scratch gets a poll result that doesn’t include 2437 in the busy line (or doesn’t even have a busy line), it knows that the command is complete and allows the script that invoked that command to proceed.
Reporters that wait (目前已實作出來) => “R"
temperature in city_name
request:/getTemperature/7639/Boston
response:_result 7639 82
Reset command
Scratch extensions can control motors or music synthesizers. Users expect to be able to stop everything — turn off motors, silence music synthesizers, and reset hardware back to it’s original state — by clicking the stop button in the Scratch editor. Thus, when the stop button is clicked, Scratch sends a reset command to all active extensions: