Condition Flags: conditional action execution

Posts: 785
Condition Flags
Condition Flags are new elements you can use in the Theme Editor for more powerful control flow of your theme. Condition flags allow you to keep track of the state of your theme, and allow you to block execution of actions when the current state of the theme should not allow it.

For example: you can use a condition flag to track if a Widget is visible, and then only allow the "Show" action if the widget is currently invisible. If the widget is already visible, the action will not execute. This is especially useful to prevent animations from running when they should not.

You can add Condition Flag items to your theme and choose to display them on you Control screen. If you do, they will show as a checkbox. You can also hide them by unchecking the "Show on controls" property.


Setting or unsetting a condition flag
Condition flag states can be either "set" (checked) or "unset" (unchecked). You can control the state of a condition flag by using the ChangeConditionFlag action, by using either the Set, Unset or Toggle effects.

If desired, you can also allow manual toggling of the condition flag by enabling the "Allow editing" property. If the condition flag item is visible on your controls screen, then you can manually toggle it by clicking on it.


Conditional action execution
To make use of the condition flags to control your theme logic flow, you can use the new Condition column in any Actions list. For each Action to execute, you can use the Condition dropdown to select the condition which must be met for the action to execute. The State checkbox next to the Condition dropdown controls whether the condition must be set (checked) or unset (unchecked) for the action to execute.

For example, this screenshot shows an action that will only be executed if the condition flag "C_VTicker" is NOT set. If the C_VTicker condition is set (checked), the action will not execute:




Syncing Buttons to a condition flags
To more easily visualize the state of a condition flag you can synchronize a button to a condition flag. Sync the button by selecting the condition flag from the dropdown in the button's Condition Flag property. When a button is synced to a condition flag, it will use the "Activated" display properties when the condition flag is set (and the regular display properties when unset). You can change the appearance of the button via the new Activated properties such as Activated Background color, Activated Font color, etc.




Reacting to condition flag state changes
A condition flag can execute its own list of actions whenever the state changes. Simply open the condition flag editor by doubleclicking in the theme explorer, or via the Actions property.
Edited (4 times)
Posts: 785
Typical usage example
The simplest usage example is to use the condition flags to block repeated execution of a certain action. For example, suppose you have a button that shows a Ticker widget with an animation. If the Ticker is already visible, you don't want this button to restart the animation. You want to block the "Show" action execution if the Ticker is already visible.

The steps needed for this kind of flow are:
  • Create a new Condition Flag (e.g. "C_Ticker"). Make sure the default State of the flag matches the default visibility of the ticket widget.
  • Create a button meant for showing the ticker.
    • Add a 'Show' widget action and specify the condition: select the C_Ticker condition and uncheck the state. This indicates: only execute the show action if the C_Ticker is unset.
    • Next, also add a 'Set' condition action and change the state of the condition to set. This action should also only execute if the condition is currently unset, so use the same condition as the show action.
  • Create a button meant for hiding the ticker.
    • Add a 'Hide' widget action and specify the condition: select the C_Ticker condition and check the state. This indicates: only execute the hide action if the C_Ticker is set.
    • Next, also add a 'Unset' condition action to change the state of the condition to unset. This action should also only execute if the condition is currently set, so use the same condition as the hide action.

Actions for the "Show" button: show the widget (but only if the condition is currently unset), and set the condition flag to indicate the ticker is now visible.


Actions for the "Hide" button: hide the widget (but only if the condition is currently set), and unset the condition flag to indicate the ticker is now hidden.
Edited (7 times)
Posts: 785
Using Scripts for more advanced condition checks
Instead of checking a single Condition Flag, you can also use a Script to check a more complicated condition, such as a combination of multiple conditions or any other condition you can check in a script. The Script works the same as a regular converter script, with the only requirement that it should return a boolean value (true or false). If it does not return a boolean value the condition check will fail (and will pass by default).

To use a script, select the script in the dropdown under the Condition check for an action.


You can check the state of other condition flags with the Theme.ConditionalFlags.CheckState method. For example, the script below checks for several conditions to be met in a certain combination.

The action should only execute if:
  • C1 is set
  • AND (either C2 is set OR C3 is unset)
  • AND the current session state is Racing

using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Enums;

namespace Scripts
{
    public class CheckCondition : IScript
    {
        public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
        {
            var c1 = item.Theme.ConditionFlags.CheckState("C1");
            var c2 = item.Theme.ConditionFlags.CheckState("C2");
            var c3 = item.Theme.ConditionFlags.CheckState("C3");

            return c1 && (c2 || !c3) && sim.Session.Current.State == SessionState.Racing;
        }
    }
}

Edited (6 times)
Posts: 53
Hello, I'd like to ask - how do I set state TRUE or FALSE to a condition flag using a script?

Thank you.
Posts: 785
Should be able to just set the Status property:

public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
var flag = item.Theme.ConditionFlags.Find("ConditionFlag1");

flag.Status = true; // checked
flag.Status = false; // unchecked

return null;
}
Posts: 287
I try to check if flag is true but nothing happen

use this

if (flag.Status == true)

----
Edit
Sorry is it that (c1 == true) to check?
var c1 = item.Theme.ConditionFlags.CheckState("C1");

if (c1 == true)
....

Test but no OK
Edited (4 times)
Posts: 785
What do you mean "not OK"? Both should work fine.
Posts: 287
I put console.writline because nothing happen, and I don't see information in event log when I do if in my script.

So you say it is correct syntax, I will try with simple fonction so and try to understand
Posts: 785
Probably something earlier in the script is causing an error and its not getting reached.
Posts: 287
Find, it is an error, it is working. Thx