Blocks action

You can use the blocks action in a trigger to create a complex response to an event or a button click. This response is created by dragging and connecting visual blocks. This gives you the full power of a programming language without having to learn syntax. 

The visual programming language is based on blockly, framework for visual programming. This is the same framework that Scratch is based on and Scratch developers may feel at home with many of the blocks. At the same time, the block editor shows the generated JavaScript code and this is an excellent way to learn how to program.

To get started with block programming create a new trigger and select the blocks action. On the action configuration, you will see the blocks editor. On the left you will see the categories of blocks you can use to construct a program, starting with Control Flow. Clicking on one of these category headers will reveal the blocks available in that category. You then drag the chosen block to the main canvas. You can also get a tooltip by hovering over a block, or if you right click on a block then a help link is available on some blocks.

Blocks can be connected into different ways: vertically, which indicates that one block will run after the other. Only some blocks, which have notches at the top and the bottom can be connected horizontally. These are the blocks that denote action steps or what programmers call “statements”.

Some blocks can also be connected horizontally, which means that values are computed. Blocks that can yield values has notches on the left-hand side; other blocks require values to specify their function, which means that they have notches on the right or internally. The blocks should assemble like a jigsaw, such that only combinations that make sense fit together. However, it is possible to construct nonsensical block assemblies.

The different categories of blocks are:

  • Control flow: blocks that introduce loops or conditional expressions. These have an inner flow that is only executed depending on a condition, in the case of the if block or an inner flow that is repeated multiple times.
  • Logic: blocks for Boolean (true or false) values and expressions.
  • Math: blocks for numbers and for arithmetic expressions.
  • Text: blocks for string constants, and a block for the name of the current channel (table name if the event type is table related).
  • Rows: blocks for manipulating row values. A row here (in javaScript, known as an object, or to python programmers, dicts or more generally, associative maps) is a collection of key-value pairs, which may come from a row in a database table. The key is always a string and the value can be any type of value. If the row comes from a database table then the key is the field name. There are blocks for creating an empty row, adding a new key value pair to an existing row (which will overwrite any existing values for that same key), getting the value at a specific key, or getting the row that is the payload in the triggering event. Are also blocks for performing database operations: query rows from tables, inserting new rows, updating existing row or deleting rows.
  • Lists: blocks for manipulating lists.
  • Actions: blocks for printing to the console (process standard output come out but captured if you do a test run) and for emitting new events
  • Variables: creating new variables with a given value, or retrieving a value in a variable