Chains

A set of blocks are functions that can pause or resume their execution while maintaining their state. You can exit the chaining process at any time, and the next time you call this function, execution will continue from where you left off. These blocks can be paused to allow other functions to do some work. They can not only be started and stopped, but also paused and resumed

../../../_images/image-19.png
  1. Execute the chain constantly - upon reaching the end, the chain will not finish its execution, but will independently go to the beginning and will be restarted an infinite number of times

Note

This block is necessary to repeat the logical construction, since the blocks added to the workspace are executed once, at the moment the block or block construction is called. You can read more about the block execution order in the corresponding article

2. Execute without waiting - the execution of this block does not block the execution of the next block in the sequence chain 3.Wait until N is true - blocks execution of the chain while the condition inside it is true

Note

As a condition, you can set any logical block

  1. Wait for N seconds - after triggering, blocks the execution of the block chain for the specified number of seconds

Note

This block is an almost complete replacement for the complex construction of blocks using a timer, the execution of which led to the execution of the following functions

  1. Wait frame - this block is triggered when the next frame is rendered
  2. Stop chain execution - the block stops the logic chain execution algorithm
  3. Start the chain again - triggering this block causes the chain to start from the very beginning

Execution of sequential actions on an example

To understand how chains work, let’s create a small project

  1. Place three objects on the scene: a cube, a cone and a pyramid. Make the objects static
../../../_images/image-27.png
  1. Go to the Blockly Logic Editor and create the following logic:
../../../_images/image-36.png
  1. Run the project in preview mode on the PC. Each block of logic is executed only after the previous one has been executed
  2. Go to the Blockly logic editor and change all sequential actions to simultaneous:
../../../_images/image-43.png
  1. Run the project in preview mode on the PC. All blocks of logic are executed simultaneously
  2. Switch to scene editing mode on PC
  3. Add a simple button below each object
../../../_images/image-51.png
  1. Go to the Blockly logic editor and change back from simultaneous to sequential
  2. Add the following logic:
../../../_images/image-62.png
  1. Run the project in preview mode on the PC. Wait until the execution of successive actions is completed - all objects will change color
  2. Click on the button below the cube. The cube will **move**along the y-axis until the button is released. To verify this, press the button again
  3. Click on the button below the cone. The cone will be scaled along the given axis. Approach the pyramid and press the button below it - nothing happened, the cone continues to scale. This is because the sequential zoom action has not completed. To do this, press the button under the cone
  4. Now press the button below the pyramid. The pyramid began to rotate around a given axis and the sequential action will end only after the button is released