Skip to main content

feature.traps

The feature.traps API allows features to access important Scratch API's in the editor.

tip

When dealing with new traps API's, we highly recommend exposing the feature variable. You can do so by finding an editor feature that uses modules and adding window.feature = feature to it.

feature.traps.vm

This API allows features to access the virtual machine in the editor. Scratch's virtual machine manages running projects, and the API is also accessible from the GUI API.

Features using the API

caution

Many or all of the features listed use the deprecated API for reaching the virtual machine. Do not reference their code when using the API for reasons other than compatability.

Feature IDUse case
start-stop-hotkeysStart and stop projects.
sprite-clonesGet the current sprite and its clones.
project-timerDetect a project starting/stopping and get the runtime.
list-spritesGet the current sprite's block count and coordinates.
last-key-pressedSee when the project detects keys pressed.
delete-spritesGet all sprites and delete them.
clone-counterGet the total number of clones.

Last updated: ScratchTools v3.1.1

feature.traps.blockly

The Blockly API controls the blocks workspace in the editor, and the blocks within the workspace itself.

Features using the API

caution

Many or all of the features listed use the deprecated API for reaching Blockly. Do not reference their code when using the API for reasons other than compatability.

Feature IDUse case
add-last-optionGet blocks to add context menu option.
block-logGet recent Blockly events.
collapse-blocksGet blocks to add context menu option.
colored-commentsGet editor comments and their parent blocks to set comment color.

Last updated: ScratchTools v3.1.1

feature.traps.gui

This is a function that returns the Scratch editor GUI, which hosts the virtual machine, important project data, and more.

Features using the API

caution

Many or all of the features listed use the deprecated API for reaching the GUI. Do not reference their code when using the API for reasons other than compatability.

Feature IDUse case
move-project-title-inputSet the title input to the project's title.
start-stop-hotkeysCheck whether or not the project is running.
slash-to-searchCheck whether or not the project is running.
unlisted-projectsGet the project ID.

Last updated: ScratchTools v3.1.1

feature.traps.paint

This is a function that returns the Scratch paint editor's API. It contains important information such as the selected shapes, opened modals, and more.

Features using the API

caution

Many or all of the features listed use the deprecated API for reaching the paint editor API. Do not reference their code when using the API for reasons other than compatability.

Feature IDUse case
special-editor-fontsSet the font of the selected item.
shared-clipboardSet and get the current clipboard data.

Last updated: ScratchTools v3.1.1

feature.traps.sound

This is a function that returns the Scratch sound editor's API. It contains important information and the ability to edit sounds.

Features using the API

caution

Many or all of the features listed use the deprecated API for reaching the sound editor API. Do not reference their code when using the API for reasons other than compatability.

Feature IDUse case
pause-audioSet the audio trimming and get the current time.
echo-effectAdd the echo effect to the current sound.

Last updated: ScratchTools v3.1.1