Working with Blockly

Introduction to Blockly

Blockly is a visual code editor that does not require programming skills. It allows writing program scripts by connecting visual blocks. The blocks are divided into groups according to their purpose or return value. Each group has its own colour. The shapes of the blocks also vary; not all the blocks are compatible. If blocks fit together, the program will run. Still, logical errors can arise in the process. The block causing the error will be illuminated. Also, when the program runs in preview mode the blocks which are executed at the moment are illuminated as well. This simplifies watching the script in real-time.

../_images/image21.png

Illuminated block (is executed at the moment)

The blocks are managed (copied, deactivated, removed, etc.) by right-clicking on them and keyboard shortcuts Ctrl+C, Ctrl+V. The blocks can be expanded and collapsed by right-clicking on them. Blockly interface consists of Workspace, where logic algorithms of the project are built, and Toolbox - side menu from whence the user may select blocks or create new ones.

../_images/image18.png

Blockly is used for composing scripts for VR projects powered by the Varwin platform. This opens access to our platform to users with no programmer skills.

Further reading

Get acquainted with Blockly

Introduction to Blockly (official site)

Training games

Standard sections

Training games have acquainted you with the standard block sections. These are used within Varwin platform:

- Logic

Main logic blocks.

../_images/image14.png

- Variables

A variable is an area of memory where to store a certain value to refer to it later. Strictly speaking, an object in itself is a variable.

../_images/image61.png

- Lists

Set of blocks allowing to work with lists. A list is a set of variables of any type.

../_images/image11.png

- Loops

Blocks allowing to set a number of actions with foregone iteration count. Can be used also to avoid lists.

../_images/image15.png

- Math

Set of blocks allowing to work with numbers.

../_images/image41.png

- Text

Set of blocks allowing to work with texts.

../_images/image10.png

- Functions

Set of blocks allowing to create and call functions. Functions are good for structuring and multiple usage of repeatable logic.

../_images/image20.png

Custom sections

These sections have been created specially for the Varwin platform.

Actions

Commands which invoke certain system actions.

../_images/image24.png

Events

All the blocks in the workspace are executed on the frame to frame basis. The exceptions are blocks from Function and Event groups. Blocks placed inside an event are executed only at the moment of an event. Events section stores general system events; e.g., on init (at the moment of initialization) event.

../_images/image17.png

Blocks that are inside this event are operated only once, at the moment of scene load or of changing the mode to Preview. This block is good for the initialization of objects state within a scene, e.g., switching on a button which is switched off by default. The block can be used multiple times.

Example

../_images/image51.png
  • сommands 1, 2 are executed only once at the moment of scene load or of changing the mode to Preview,
  • command 3 is executed frame by frame,
  • command 4 is executed at the moment of event (pressing on the panel.)

Objects

Objects spawned on the scene in VR are displayed in this section. Available states (variables) for each object are shown as well (ill. 1) - object:any is a section with blocks that can be applied to any object. - Objects added to a scene are grouped by type (ill.2: area, button, display, etc.) The specific object can be selected from the drop-down list (ill.3)

../_images/image71.png

ill.1

../_images/image81.png

ill.2

../_images/image31.png

ill.3

Blocks for objects

Section Name Purpose Picture
Logic checker Check true/false ../_images/image22.png
Action action Actions with object ../_images/image13.png
Variables getter Get a state ../_images/image221.png
setter Set a state ../_images/image23.png
Events event Events with object ../_images/image12.png

Creating custom blocks

Custom blocks can be created along with object code. See an example here: Creating objects for Varwin in Unity - Example

How Blockly works on Varwin platform

To open Blockly,

  • Open relevant project,
  • Click “Open visual logic editor”.
../_images/image19.png

You may proceed to creating algorithms.

../_images/image111.png

The new algorithm can be immediately checked in VR. To do it, click ‘Run in VR.’

../_images/image16.png

Logic set in the script is executed in VR frame by frame, except Function and Event blocks.