程序總覽
在電腦科學術語中,程序是指執行特定任務的可重複使用的一小段程式碼。
區塊會實作程序,做為一組區塊,用於產生定義程序及呼叫程序。

→ 進一步瞭解如何使用區塊。
→ 進一步瞭解如何建立自訂程序區塊。
→ 進一步瞭解如何建立自訂程序模型,以便新增類型參數等新功能。
內建與外掛程式的差異
Blockly 提供兩項程序區塊的實作。
外掛程式 @blockly/block-shareable-procedures 外掛程式就會實作仰賴備份資料模型的程序區塊。這可讓您透過程序區塊執行多項操作,例如將定義區塊存在於某個工作區中,而呼叫區塊存在於另一個工作區。外掛程式是程序區塊的建議實作方式。
另一種是 Blockly 核心提供的舊版實作方式。這些區塊沒有備份資料模型,所有程序相關資訊都來自區塊本身。工作區僅會檢查工作區包含的程序定義區塊,才能確認可執行哪些程序。系統會繼續支援這些區塊,確保回溯相容性,但大多數開發人員都應能使用外掛程式提供的新區塊。
如果您使用的是 XML 序列化作業,您可以使用新的區塊,但無法在不同工作區之間共用這些區塊。該功能需要 JSON 序列化程式僅提供的額外序列化作業。使用 XML 時,新區塊的運作方式將與舊版區塊相同。進一步瞭解如何升級至 JSON。
如果您已定義自訂程序區塊,就必須更新該區塊,才能使用新的資料模型。
如果您已定義自訂程序定義區塊,但使用的是內建程序呼叫區塊,則在您更新定義區塊之前,必須繼續使用舊版呼叫區塊。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2023-12-02 (世界標準時間)。
[null,null,["上次更新時間:2023-12-02 (世界標準時間)。"],[[["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"]]