这个是开发scratch插件的文档,以下是英文原文,比较简单,所以也就没有翻译。
这是个好东西,懂的拿去。
Creating Scratch 2.0 Extensions
John Maloney
MIT Media Laboratory
September, 2013
NOTE 1: This specification supersedes all earlier drafts.
NOTE 2: This specification is still preliminary and may change.
Introduction
Scratch 2.0 can be extended to control external devices (e.g. robotics kits, musical instruments) and
to access data from external sensor hardware (e.g. sensor boards). A Scratch 2.0 extension extends
Scratch with a collection of command and reporter blocks that can be used to interact with a
particular device. When an extension is enabled, its blocks appear in the "More Blocks" palette.
Due to browser security restrictions, Scratch 2.0 cannot interact with hardware devices directly.
Instead, hardware extensions come with a helper app, a separate application that the user must
install and run on their computer. Scratch communicates with the helper app via HTTP requests,
and the helper app talks to the hardware. In the future, some extensions may package their helper
apps as browser plugins, but that mechanism is not described here.
This document is aimed at Scratch 2.0 extension developers. It describes the extension description
file format, the protocol used to communicate between Scratch extension helper apps, and the
extension development process.
Extension description file
An extension description file is a text file in JSON format (http://www.json.org) that describes the
extension. By convention, a Scratch 2.0 extension file ends in .s2e.
The JSON object in the extension description file includes the extension's name, the TCP/IP port
number used to communicate with the extensions helper app, and a list of Scratch block
specifications.
Here is an example:
{ "extensionName": "Extension Example",
"extensionPort": 12345,
"blockSpecs": [
[" ", "beep", "playBeep"],
[" ", "set beep volume to %n", "setVolume", 5],
["r", "beep volume", "volume"],
]
}
This extension's name is "Extension Example" and it connects to its helper app on port 12345. The
"blockSpecs" field describes the extension blocks that will appear in the "More Blocks" palette. In
this case, there are three blocks: (1) a command block that plays a beep; (2) a command block that
sets the beep volume; and (3) a reporter (value-returning block) that reports the current beep
volume setting.
Block description
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)
"b" - boolean reporter block (pointy 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)
全文太长了发不出去,以上是部分内容,
这里提供pdf电子版下载地址:http://www.scratch100.com/thread-4-1-1.html
这是个好东西,懂的拿去。
Creating Scratch 2.0 Extensions
John Maloney
MIT Media Laboratory
September, 2013
NOTE 1: This specification supersedes all earlier drafts.
NOTE 2: This specification is still preliminary and may change.
Introduction
Scratch 2.0 can be extended to control external devices (e.g. robotics kits, musical instruments) and
to access data from external sensor hardware (e.g. sensor boards). A Scratch 2.0 extension extends
Scratch with a collection of command and reporter blocks that can be used to interact with a
particular device. When an extension is enabled, its blocks appear in the "More Blocks" palette.
Due to browser security restrictions, Scratch 2.0 cannot interact with hardware devices directly.
Instead, hardware extensions come with a helper app, a separate application that the user must
install and run on their computer. Scratch communicates with the helper app via HTTP requests,
and the helper app talks to the hardware. In the future, some extensions may package their helper
apps as browser plugins, but that mechanism is not described here.
This document is aimed at Scratch 2.0 extension developers. It describes the extension description
file format, the protocol used to communicate between Scratch extension helper apps, and the
extension development process.
Extension description file
An extension description file is a text file in JSON format (http://www.json.org) that describes the
extension. By convention, a Scratch 2.0 extension file ends in .s2e.
The JSON object in the extension description file includes the extension's name, the TCP/IP port
number used to communicate with the extensions helper app, and a list of Scratch block
specifications.
Here is an example:
{ "extensionName": "Extension Example",
"extensionPort": 12345,
"blockSpecs": [
[" ", "beep", "playBeep"],
[" ", "set beep volume to %n", "setVolume", 5],
["r", "beep volume", "volume"],
]
}
This extension's name is "Extension Example" and it connects to its helper app on port 12345. The
"blockSpecs" field describes the extension blocks that will appear in the "More Blocks" palette. In
this case, there are three blocks: (1) a command block that plays a beep; (2) a command block that
sets the beep volume; and (3) a reporter (value-returning block) that reports the current beep
volume setting.
Block description
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)
"b" - boolean reporter block (pointy 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)
全文太长了发不出去,以上是部分内容,
这里提供pdf电子版下载地址:http://www.scratch100.com/thread-4-1-1.html