import{javascriptGenerator}from'blockly/javascript';javascriptGenerator.forBlock['my_custom_block']=function(block,generator){// Get the field value.constfieldValue=block.getFieldValue('MY_FIELD');// Concatenate the code.constcode=`some code ${fieldValue} some more code`;// Return the code.returncode;}
// For a single line text field.conststr=generator.quote_(block.getFieldValue('STR'));// For a multiline text field.conststr=generator.multiline_quote_(block.getFieldValue('STR'));
[null,null,["最后更新时间 (UTC):2024-09-09。"],[[["Fields in Blockly define user-editable values (strings, numbers, colors, etc.) for code generation."],["Access field values using `getFieldValue`, transform them into usable strings (e.g., quoting strings, scrubbing variable names), and concatenate them into the code."],["Use `quote_` or `multiline_quote_` to properly format string values for code generation."],["Use `getVariableName` to ensure variable names are valid and avoid conflicts in the generated code."],["Refer to specific block type documentation for details on returning the generated code."]]],["Code generation with fields involves retrieving user-inputted values, such as strings or numbers, from fields. `getFieldValue` accesses these values, which vary by field type. Strings need quoting via `quote_` or `multiline_quote_`, while variables require scrubbing with `getVariableName` to ensure they are ASCII and don't clash with reserved words. Finally, the processed field value is inserted into the code string. The completed code string is returned depending on the specific type of block.\n"]]