Setting Preconditions for Actions

You can set preconditions on model actions in Eggplant AI so that the action can't be called during a model run unless specific conditions are met. For instance, you might have a button in your UI that becomes active only if you enter text in a field first. In this case, you could use a precondition on the button action to ensure the model couldn't call it unless the field text was entered first. Another use case might be if you have a global action that shouldn't be called from a certain state.

Setting an action precondition involves three steps:

Create a Variable

Variables for preconditions are created the same as any other variable. The variable can be a state variable or a global variable. Your choice will be based on the condition you want the model execution to meet before performing the action.

If the precondition is based on another action within the same state, you'll use a state variable. For instance, you might have a login screen where a username and password must be entered before you can click the OK button. If you build your model such that each of those is a separate action, then both the username action and the password action could be set as preconditions to the OK action, using state variables.

An Eggplant AI model state for a login screen

An Eggplant AI model state for a login screen

You could use a global variable as a precondition for something that happens at one point in your model but could block the actions in multiple other places. For instance, you might need a user to log in to the system to access some features but not others. In this case, you would set the global variable when the log in action takes place, then use that as the precondition for each action elsewhere in the model that requires a logged in user.

Tip: The currentState variable is a special predefined global variable that contains the name of the current state. You can use this variable to prevent a global action from being called from a specific state. For instance, if you have a global action for Quit, you might want to block that action from being called from your Initial state.

For information about creating variables, see State Variables Section.

Set the Evaluation Condition

To meet a precondition before accessing an action, you set an evaluation condition for a variable. If the value for the variable isn't correct, the given action can't be called by the model execution.

You set the evaluation condition on the Action Properties tab in the Preconditions for this Action to Execute section. Follow these steps to set an evaluation condition:

  1. Select the action in the Model tab that you want to apply a precondition to. In the right pane, the Action Properties tab should become the focus. In the Preconditions for this Action to Execute section, you'll see a listing of all the state variables and global variables available to the selected action.
  2. For the variable you want to evaluate against, select the evaluation condition from the Condition drop-down menu.
  3. In the Value field, enter or select the value to evaluate against. The value you enter should be consistent with the variable type, which is shown in the Type field.

Note that you can set a precondition on multiple variables for a single action.

For more information about the Preconditions section on the Action Properties tab, see Preconditions for this Action to Execute Section.

Set or Change Variable Value

A precondition evaluation is based on a variable having a specified value. You can change the value of a variable when it encounters a specific action in the model by using the Set and Generate Variable Values section on the Action Properties tab. Follow these steps to set or change a variable value during model execution:

  1. Select the action in the Model tab that you want to use to trigger a variable value change. In the right pane, the Action Properties tab should become the focus. In the Set and Generate Variable Values section, you'll see a listing of all the state variables and global variables available to the selected action.
    The Set and Generate Variable Values section of Action Properties in Eggplant AI
  2. For the variable you want to change, select the change type from the Operation drop-down menu:
    • set: Use this option to select a specific value. When you're using this capability for preconditions, this option will mostly likely be the right choice.
    • generate: Use this option if you want to generate a value based on criteria appropriate to the variable type.
  3. In the Value field, enter or select the value to set for the variable. The value you enter should be consistent with the variable type, which is shown in the Type field.

In addition to using the Set and Generate Variable Values section to change variable values, you can pass variables to SenseTalk snippets to affect their values, then use those variables as preconditions for actions.

For more information about the Generate Variable section of the Action Properties tab, see Set and Generate Variable Values.

 

This topic was last updated on August 19, 2021, at 03:30:47 PM.

Eggplant icon Eggplantsoftware.com | Documentation Home | User Forums | Support | Copyright © 2022 Eggplant