Introduction | Your first interface | Building a model | Advanced features | Resources

4.8 Triggers and overlays

This section provides an example of how to implement triggers and overlays. A trigger is a condition of a model variable that causes something to happen. For instance, if you have a counter that counts from 0 to 10, you could set counter = 10 as a trigger for the counter to reset. An overlay can be thought of as a transparency covering the canvas on which objects are placed. Overlays can be visible or invisible while the simulation is running. The real power of triggers and overlays comes from setting triggers for when overlays display.

The model and interface used in this section can be downloaded here: trainingTriggersOverlays.zip.

The example below does a very basic conversion between hours and minutes to minutes only, but it shows how to use overlays by implementing two, the visibility of each decided by a trigger condition. The 'Show/hide help' boolean button makes a help overlay visible or hidden depending on the user-selected state of the variable. A second overlay is used to provide feedback on errors if an error variable is set to true (try setting minutes to greater than 60).

Trigger conditions

You can add, edit, and delete trigger conditions using the Trigger Management Control panel (View / Trigger Conditions).

The Add trigger condition and Edit buttons display a calculator-style panel in which you can create a trigger condition or modify an existing condition. The Delete buttons allow trigger conditions to be removed, but only trigger conditions which are not in use can be deleted.

By default, the value of the trigger condition is based on the current state of the model, whether the simulation is in run mode or edit mode. By changing this value from Model to True or False, the value of the trigger condition while in edit mode can be overridden for testing purposes.

When you are creating or editing trigger conditions, you will use the Trigger Condition Editor, which allows you to construct an expression that will evaluate to true or false. You can use numeric or boolean model properties as the basis for this expression.

You may need to use parentheses to construct more complex expressions, but these can only be nested to a level of five deep.

Note that checking trigger conditions incurs a computational cost, so if your simulation includes loads of triggered overlays it might not run as fast as you thought it would.

As well as overlays, link buttons, popup buttons and action buttons can have trigger conditions associated with them. In these cases, when the trigger condition is met, it is equivalent to the button being pressed.

Overlays

Overlays can be added and selected for editing using the Overlay editor.

Overlays can be added using the New button, and the Delete button will allow you to delete the currently selected overlay. When the edit option button for an overlay is selected, items can be added or removed from that overlay. Note that you will still be able to see items on the main interface when an overlay is selected, but will not be able to select or edit them. The overlay panel must remain open while overlays are being edited. When the panel is closed the tool reverts back to editing the main interface, and objects on overlays will no longer be accessible. You can close the Overlay Editor with the Finished button.

If the Visibility check box for an overlay is selected that overlay will be visible. An overlay can be visible without being editable, so be sure you have the correct overlay selected for edit before you start. Each overlay is independent so any combination could theoretically be displayed at any one time. The Trigger conditions button will bring up the Select Trigger Condition dialog, in which you can set an existing trigger condition, or create a new one, to determine when the overlay is visible.