Block Coding
Block coding implements math, date/time operations, text processing, unit conversions, and more by combining blocks.
General
Block coding can be used in every value input in logic. Clicking the button on the right side of a value input offers four input methods.
- Direct entry: Enter the value as-is.
- Variable value: Use another variable's current value.
- Block editor: Use the result calculated by assembled blocks.
- Lua script: Write Lua code and use its
returnvalue.
All four methods must return a value matching the input's type; a mismatched type causes an error at execution time.
Block Editor
Select Block Editor and click Edit Block to open the editor. The editor consists of a toolbox, where blocks are organized by category, and a workspace, where blocks are connected together.
Working with Blocks
- The return block is already placed in the workspace and is the only path for sending a result out of the block editor. The type of the value connected to it must match the type of the value input.
- Most blocks have inputs or outputs (some have neither). Blocks with outputs are dragged and connected to other blocks' inputs.
- Inputs and outputs have data types, and only matching types can be connected. The data types are the same as variable types.
- Hovering over a block shows its description as a tooltip; right-clicking shows the available commands.
- Blocks with a variable number of inputs (if, text join, list creation, local function parameters, and so on) use the block's gear button to add, remove, or reorder entries.
- Connecting a new block to an input that already holds one pushes the existing block out.
- Shadow blocks are pre-filled for convenience and are deleted automatically when replaced by another block.
- A finished assembly must be fully connected; empty inputs or outputs cause errors at execution time.
- Blocks stacked vertically execute in order from top to bottom, and conditional statements and loops enable more complex calculations.
- The break/continue block can only be used inside a loop block, and a local function's return if block only inside a local function.
Blocks
The toolbox consists of 18 functional categories. Typing a name or description into the search box at the top of the editor narrows the view to the matching blocks, and each block's description is shown as a tooltip when hovering over it.
| Category | Contents |
|---|---|
| Variables | Blocks that read and write project variables. |
| Logic | Conditional statements (if), comparison, and boolean operations. |
| Loops | Count, condition, counting, and list loops, plus break/continue. |
| Math | Arithmetic and mathematical functions. |
| Date/Time | Date and time calculations and conversions. |
| Text | String manipulation. |
| Byte Arrays | Binary data manipulation. |
| Lists | List creation, lookup, and manipulation. |
| Type Conversion | Conversion between variable types. |
| Unit Conversion | Length, pressure, energy, speed, temperature, astronomical distance, angle, coordinate (deg/min/sec), and compass conversions. |
| Science | Sun and moon rise/set times, azimuth and altitude, psychrometric properties, and standard atmospheric pressure. |
| Bits/Bytes | Bitwise operations. |
| Complex/Vector | Complex number and vector operations. |
| JSON | JSON parsing and generation. |
| XML | XML parsing and generation. |
| Color | Color value manipulation and conversion. |
| Local Variables | Temporary variables scoped to this block editor. |
| Local Functions | Functions defined and called within this block editor. |
Local Variables and Local Functions
Local variables exist only inside the block editor that defines them and are used to hold intermediate results. They are separate from project variables, so other logic and dashboards cannot see them. Blocks are provided to create a variable, write a value, read a value, and add a number. The counting and list loops in the Loops category work by storing the index or item in a local variable.
Local functions are for calculations repeated in several places. Functions with and without a return value can be defined, and input parameters are added with the block's gear button. A defined function is run from another block in the same editor using a call block, which also comes in two forms depending on whether a value is returned. To return a value part-way through a function, use the return if block.