Update set.js

This commit is contained in:
Tyler Cooper 2025-08-07 15:40:06 -05:00 committed by GitHub
parent 4b2b8705f7
commit 63be361898
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,35 +5,31 @@ export default {
name: "Set Variable", name: "Set Variable",
inputsInline: true, inputsInline: true,
colour: 240, colour: 240,
description: "Set a variable to a value", description: "Store a value in a named variable for later use in your Action. Variables let you remember feed values, calculation results, or any data to use in subsequent action blocks.",
connections: { connections: {
mode: 'statement', mode: 'statement',
output: "expression", output: "expression",
next: "expression", next: "expression",
}, },
template: "Set variable %VAR = %VALUE", template: "Set variable %VAR = %VALUE",
inputs: { inputs: {
VALUE: { VALUE: {
description: "The value to store in the variable. This can be text, numbers, feed values, calculation results, or data from other blocks.",
check: "expression", check: "expression",
shadow: "io_text", shadow: "io_text",
} }
}, },
fields: { fields: {
VAR: { VAR: {
description: "Choose or create a variable name to store the value. Use descriptive names like 'temperature_reading' or 'user_count' to make your Actions easier to understand.",
type: 'field_variable' type: 'field_variable'
} }
}, },
generators: { generators: {
json: (block, generator) => { json: (block, generator) => {
const const
variableName = block.getField('VAR').getText(), variableName = block.getField('VAR').getText(),
value = generator.valueToCode(block, 'VALUE', 0) value = generator.valueToCode(block, 'VALUE', 0)
const const
// TODO: this is suspect, try valueToCode() || null, above // TODO: this is suspect, try valueToCode() || null, above
defaultedValue = value defaultedValue = value
@ -46,17 +42,14 @@ export default {
value: defaultedValue value: defaultedValue
} }
}) })
return blockPayload return blockPayload
} }
}, },
regenerators: { regenerators: {
json: (blockObject, helpers) => { json: (blockObject, helpers) => {
const const
{ name, value } = blockObject.setVariable, { name, value } = blockObject.setVariable,
id = helpers.registerVariable(name) id = helpers.registerVariable(name)
return { return {
type: "io_variables_set", type: "io_variables_set",
fields: { fields: {