Overview of procedures
Stay organized with collections
Save and categorize content based on your preferences.
In computer science terms, a procedure is a reusable bit of code that performs a
specific task.
Blockly implements procedures as a set of blocks that generate code for defining
a procedure, and calling it.

→ More info on using the blocks.
→ More info on creating custom procedure blocks.
→ More info on creating custom procedure models, which allow you to add new functionality like typed parameters.
Built-in vs plugin
Blockly provides two implementations of procedure blocks.
One exists in the plugin @blockly/block-shareable-procedures,
which implements procedure blocks that rely on a backing data model. This allows
you to do things with your procedure blocks such as having the definition
block exist in one workspace, and the call block exist in another. The plugin is
the recommended implementation of procedure blocks.
The other is the legacy implementation, provided in Blockly core. These blocks
don't have a backing data model, and all information about procedures comes
from the blocks themselves. The only way a workspace knows which procedures
are available is by inspecting the procedure definition blocks contained in
that workspace. These blocks continue to be supported for backwards
compatibility, but most developers should be able to use the new blocks
provided by the plugin.
If you are using XML serialization, you can use the new blocks, but they
won't be shareable across workspaces. That feature requires extra serialization
that is only provided by the JSON serializer. When using XML, the new blocks
will behave identically to the legacy blocks.
Learn more about upgrading to JSON.
If you have defined custom procedure blocks, they need to be
updated
to work with the new data models.
If you have defined custom procedure definition blocks, but are using the
built-in procedure call block, you need to continue using the legacy caller
block until you update
your definition block.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-18 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-18 UTC."],[[["In Blockly, procedures are reusable code blocks that execute specific tasks, allowing users to define and call them within their projects."],["Blockly offers two procedure block implementations: a recommended plugin-based approach with data models for advanced features and a legacy core implementation for backward compatibility."],["The plugin-based implementation enables procedure sharing across workspaces when utilizing JSON serialization, whereas XML serialization limits sharing but functions similarly to legacy blocks."],["Custom procedure blocks require updates to ensure compatibility with the newer data models introduced by the plugin-based implementation."],["When using custom procedure definition blocks with built-in procedure call blocks, it's necessary to retain the legacy caller block until the definition block is updated for compatibility."]]],["Blockly uses blocks to define and call procedures, which are reusable code segments. It offers two implementations: a recommended plugin (@blockly/block-shareable-procedures) with a backing data model for features like cross-workspace sharing, and a legacy core implementation without a data model. The plugin blocks support JSON serialization for sharing; XML serialization is limited. Custom procedure blocks must be updated to use the new data models. Custom definition blocks used with the built-in caller block should use legacy caller blocks until the definition block is updated.\n"]]