This block will trigger a flag with a specified address.
Trigger the flag can accept a number. Numbers can range from -9999 to 9999.
Working example for Trigger the flag usage. Note that Trigger the flag and Start when the flag is triggered blocks have the same address (1).
Example with incorrect logic. Note that Trigger the flag and Start when the flag is triggered blocks have different addresses. In this case, Sound will not be played because there is no code, that would trigger a flag with address 1.
LEGO® Powered UP App coding example: Trigger the flag using If / Else statement block
Step 1: Add coding blocks
- Flow block – Start
- Flow block – If / Else statement, set condition to
false
- Flow block – Trigger the flag with address 1
- Flow block – Trigger the flag with address 2
- Flow block – Start when the flag is triggered width address 1 + Sound and light Play from the whistle sound library
- Flow block – Start when the flag is triggered width address 2 + Sound and light Play from the car sound library
Step 2: Run the program. Observe that only Play from the car sound library block is executed, because a flag on address 2 is triggered. When If / Else statement input value is changed to true
, then only Play from the whistle sound library block is executed.
Trigger the flag is not that usefull in simple programs. But when the program grows, and there is a need to execute complex logic chains Trigger the flag helps to avoid using repetitive coding strips, or placing long coding strips into If / Else statement blocks or other repeat blocks.