Skip to main content

Custom Fields API

important notes

the object that contains every single custom field type is structured as {[fieldName]: info}, where fieldName is the name of the field (and therefor also the name used in the type key in an argument)

keytypefunction
outputString | Array<String> | nullthe output type of this fields allowReporters mode as supported by the blockly block json format
outputShapeScratch.BlockShapethe block shape of this fields allowreporters mode
implementationBlockly.Fieldthe field (as an extension of the Blockly.Field class) to be registered to blockly

note that as of currently you will need to make your own listner for Runtime.EXTENSION_FIELD_ADDED that registers the field to blockly (the data recieved in the event is { name: String, implementation: Blockly.Field }), below is a code snippet to do this

Scratch.vm.on('EXTENSION_FIELD_ADDED', ({ name, implementation }) => {
ScratchBlocks.Field.register(name, implementation);
});