Skip to content
Nihal Mittal edited this page Mar 10, 2020 · 6 revisions

Tutorial for create a program with events

This type of program have different blocks, these blocks are when blocks, these work like a event, when a condition is true this is execute.

Below is shown how you can create this type of programs.

Open a example

In folder learnbot_dsl/learnbotCode/examples/ there are some examples. We can open the example follow_red_line_with_events.blockProject with the Learnblock program .

Example follow red line with events

In order to execute this example you should check the checkbox Used Events.

This example have 5 when blocks.

No line

This block is executed when the robot doesn't see the red line.

Red line right

This block is executed when the robot sees the red line on its right.

Red line left

This block is executed when the robot sees the red line on its left.

Red line center

This block is executed when the robot sees the red line on its center.

Line crossing

This block is executed when the robot sees the red line cross with black line.

Create your own when block

In Learnblock, with the checkbox Used Events checked, you can push button Add When in control panel.

Then you should choose the type and the name of the block.

There are two type of blocks:

block8

This type need a condition and when condition is true the block is activated.

Imagen block8

block10

This type have two functions Activate nameWhen and Deactivate nameWhen for active and deactivate the block.

Imagen block10

Both have a variable with its own the time of execution. It is restartes when the block is deactivated and its value is 0.