Scratch object API
The global Scratch object is how an extension talks to RemixWarp. It carries the registration function, the type constants, casting helpers, and (for unsandboxed extensions) direct access to the VM and permission APIs.
Sandboxed extensions get a limited Scratch; the VM, renderer, and block utility are unsandboxed only.
Registration and structure
(function(Scratch) {
'use strict';
class MyExtension {
getInfo() {
return {
id: 'myextension',
name: 'My Extension',
blocks: [
{
opcode: 'myBlock',
blockType: Scratch.BlockType.REPORTER,
text: 'convert [VALUE] to number',
arguments: { VALUE: { type: Scratch.ArgumentType.STRING, defaultValue: '42' } }
}
]
};
}
myBlock(args) {
return Scratch.Cast.toNumber(args.VALUE);
}
}
Scratch.extensions.register(new MyExtension());
})(Scratch);
Scratch.extensions.register(instance): register your extension. Call it exactly once.Scratch.extensions.unsandboxed:truewhen running unsandboxed. Check it before using any unsandboxed-only API.
Type constants
Scratch.BlockType
| Constant | Value | Meaning |
|---|---|---|
COMMAND | command | Stack block, no return value |
REPORTER | reporter | Round block returning a string or number |
BOOLEAN | Boolean | Hexagonal block returning true/false |
HAT | hat | Conditionally starts a stack (see Events and hats) |
EVENT | event | Starts a stack on an event; has no function |
CONDITIONAL | conditional | if/else style C block (see Custom C blocks) |
LOOP | loop | repeat/forever style C block |
BUTTON | button | A palette button, not a real block |
LABEL | label | A text label in the palette, not a real block |
XML | xml | Raw Blockly XML |
Scratch.ArgumentType
STRING, NUMBER, BOOLEAN, COLOR, ANGLE, MATRIX, NOTE, COSTUME, SOUND, IMAGE. See Dealing with inputs for what each accepts.
Scratch.TargetType
SPRITE ('sprite') and STAGE ('stage'), used with a block's filter.