調査アンケート: Blockly のご利用体験についてお聞かせください
アンケートを開始
明細
ステートメント ブロックは、出力接続のないブロックです。これらは
記述できます。
Blockly のすべてのブロックと同様に、ステートメント ブロックもコードに変換できます。
ブロックコード ジェネレータを定義して、文字列を文字列に変換できます。
import {javascriptGenerator} from 'blockly/javascript';
javascriptGenerator.forBlock['custom_block'] = function(block, generator) {
// Collect argument strings.
const fieldValue = block.getFieldValue('MY_FIELD');
const innerCode = generator.statementToCode(block, 'MY_STATEMENT_INPUT');
// Return code.
return 'my code string';
}
引数文字列を収集する
すべてのブロックコード生成ツールでは、
フィールドの値を収集し、
作成します。
// Collect field values.
const fieldValue = block.getFieldValue('MY_FIELD');
// Collect inner block code strings.
const innerCode = generator.statementToCode(block, 'MY_STATEMENT_INPUT');
内側のブロックのコードを複数回参照する場合は、
引数のキャッシュ保存をブロックに追加します。
戻り値
ステートメントのブロックコード ジェネレータの戻り値の型はコード文字列です。
return 'my code string';
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2024-10-15 UTC。
[null,null,["最終更新日 2024-10-15 UTC。"],[[["Statement blocks in Blockly, similar to statements in text-based languages, lack output connections and function by defining a block-code generator to convert them into code strings."],["Generating code for statement blocks involves collecting values from fields and inner blocks using dedicated functions within the block-code generator."],["Block-code generators for statement blocks return code strings, representing the translated code for the block, and optionally incorporate argument caching for optimized code generation."]]],["Statement blocks, which lack output connections, are converted to code strings using block-code generators. This process involves collecting values from fields and code from inner blocks. The `getFieldValue` method retrieves field values, while `statementToCode` gathers inner block code. If inner block code is used multiple times, argument caching is recommended. Ultimately, a statement block-code generator returns a string representing the generated code.\n"]]