← BACK

A trigger allows you to perform logic, typically during a transition, when certain conditions are met. Since triggers are activated through gestures that the user performs during the demo, it is helpful to think of triggers as special types of advanced gestures.

Unlike regular gestures that follow a pre-defined transition sequence and move to the scene that you select when you add them, gestures with triggers don’t include any transitions in their properties. These gestures rely on their triggers to perform transitional logic, using alternative flows, including randomizing transitions.

Note: A transition with a trigger conditional always takes precedence over any other transitions from the same scene with equal probability.

It is also helpful to think of a trigger as an invisible light switch. It is turned on when the user gesture activates the trigger. It remains on until you turn it off (clear the trigger). When designing your transition logic, you can check if a particular trigger was set and perform an action, such as showing an element, and/or transition to the next scene accordingly. For example, see Use Case 1 below.

You may also associate a time frame with triggers. For example, if the user interacts with the demo within the specified time, a predefined transition or action occurs. If time elapses and the user fails to interact with the demo, the demo transitions to an alternate flow. 

If desired, you may also have several graduated time periods associated with the same trigger. Each elapsed time period would typically have an alternate transition flow, including randomized transitions. For example, see Use Case 2 below.

Important: It’s a best practice to use triggers only in the scene in which you set them and explicitly clear all triggers upon the exit from the scene.

The overall process of using a trigger to perform logic includes the following tasks:

  1. In the selected scene where you want to define advanced logic, set a trigger, typically associated with a gesture.
    The gesture may have other actions, such as Show Element.
  2. In the Events & Actions panel of the same scene, add multiple transitions using the trigger conditionals and, if needed, randomize the transitions. 
  3. If no continuation of experience is expected, clear the trigger.

Below are step-by-step instructions and use case examples.

Set a Trigger

To create a trigger in Studio, all you need to do is to name it using the Set Trigger action menu. Depending on your design, you can access this menu by selecting  Add an Action > Set Trigger in one of the following panels:

  • The Events & Actions panel, if you are setting a trigger for a scene.
  • The Gesture Element Properties panel, if you are setting a trigger for a gesture.

To set a trigger for a gesture:

  1. Go to Scenes and select a scene that requires a gesture with a trigger.
  2. Add the desired gesture and specify its name and type (for example, tap). If necessary, see Add Gestures for details.
  3. Go to the Gesture Element Properties panel, click Add an Action and select Set Trigger.
    The Set Trigger action menu appears in the Actions section of the gesture properties.

  4. In the Trigger drop-down list, select New Trigger.
  5. In the displayed dialog, enter a descriptive name for the trigger without using special characters or capital letters and click OK.

    The new trigger is automatically selected in the Trigger drop-down list.

  6. Save the project.

After you set a trigger, you can use it to define the desired transition logic. The following use cases provide different examples of how you can do it.

Use Case 1—True/False Trigger Conditionals

A demo includes a combat scene in which the user tries to attack a haunted temple. In this scene, you want the combat video to play to the end regardless of what the user does, with no immediate transitions. You want, however, to display an icon on the screen every time the user successfully interacts with the demo and set a trigger.

At the end of the video, you need to check if any triggers were set. Thus, if the user successfully attacked (trigger is set), the demo moves to a success scene that shows the results of the attack. If there are no triggers set, the demo moves to the failed attack scene.

To accomplish this, you need to do the following in the Combat scene:

  1. Add the image icon to appear for each successful user interaction.
  2. Add a gesture element to the canvas and in its Properties select the gesture type, for example, tap. 
  3. Add two actions to the gesture—Set Trigger and Show Element (for the icon on the screen).

    Note: The icon element layer must be set as invisible in the Layers panel.

  4. Go to Events & Actions and add a transition to a Failed Attack scene. Keep the default After Video event and 100% Probability settings.
  5. Depending on your design, add at least one transition to a Successful Attack scene. The same scene may have several videos.
  6. Click the Conditional icon. Keep the default After Video event and 100% Probability settings.
  7. In the Transition menu, next to Trigger Conditionals, click Add  and select the Trigger you set for the gesture in step 3.
    For example, your settings may look like this:

  8. Save the project.
  9. (Optional) Click Path View to see the transitions you have defined.

In Path View, the transitions for the use case above should appear similar to the ones shown below.

With this setup, if the trigger is set when the user taps the screen, the demo will eventually transition to a Successful Attack scene after the combat video ends and play one of its videos.

Use Case 2—Timed Trigger Conditionals

A demo includes a baseball scene in which a pitcher throws a ball, and the user needs to tap it to swing. If the user doesn’t tap within a specific time frame, the demo moves to the Strike scene. If the user does tap, timing becomes critical for the transition logic in this scenario, as the demo moves to an alternate scene based on how fast the user taps.

For example, if the user swings before one second elapses, the demo immediately moves to the Really Early Swing scene. If the user swings between one second and 1.1 seconds, the ball goes foul down on the left field line, and so on as shown in the diagram below.

Tip: To support more random outcomes, for example, when the ball goes into play after the user taps between 1.1 and 1.5 seconds, you may consider adding randomized transitions.

You can design a demo with a scene like this in either of the following ways:

  • By adding tap gestures for each transition and then using the At Time event settings for each gesture layer in the Events & Actions panel to time each 1:1 transition, including the randomized ones.
  • By using a single timed trigger to determine a more variable outcome for all transitions. The steps below describe this process.

To use a timed trigger, you need to do the following in the Pitching scene:

  1. Add a gesture element to the appropriate location on the canvas.
  2. Go to Properties, select the Tap gesture type, and set a trigger for it.
  3. Go to Events & Actions, add a transition and click the Conditional  icon in its transition block.
  4. In the displayed Transition action menu, do the following:
    1. Clear the After Video event.
      This ensures that the transition will occurs as soon as the user taps within the specified time frame.
    2. Select the appropriate Move to Scene.
    3. Select the Before Second checkbox and enter the appropriate decimal or integer to indicate the maximum time that can elapse for the transition to occur.
      For example, for the transition to the Really Early Swing scene, enter 1; for the transition to the Home Run Scene, enter 1.5, and so on. For details on how to calculate and enter values in these fields, see Elapsed Time Values.
    4. Select the After Second checkbox and enter the appropriate decimal or integer to indicate the minimum time that needs to elapse before the transition can occur.
      For example, for the transition to the Really Early Swing scene, leave this field blank; for the transition to the Home Run Scene, enter 1.1, and so on.
    5. Next to Trigger Conditionals, click Add  and select the Trigger you set for the gesture in step 2.
      For example, your settings for the transition to the Foul Down Left scene may look like this:

  5. Repeat steps 3 and 4 for each alternate transition in the sequence within the desired time frame.
  6. To randomize transitions, for example, 40% Home Run, 30% Double, 15% Single, 10% pop out, and 5% ground, as shown in the diagram in Randomized Transitions, add a transition for each alternate scene, with the same trigger time frame but with different decimals in the Probability fields.
  7. Save the project.
  8. (Optional) Click Path View to see the transitions you have defined.

In Path View, the transitions for the use case above should appear similar to the ones shown below.

Clear a Trigger

Since triggers should be used only in the scenes in which you set them, you need to clear them at the end of each scene, regardless of whether you set the triggers at the scene or gesture level.

To clear a trigger:

  1. Go to Scenes and select a scene where you need to clear a trigger.
  2. Go to Events & Actions, click Add an Action, and select Clear Trigger.
  3. In the displayed action block, click On Exit.

    The location of the Clear Trigger action block may change in the Events & Actions list to reflect the execution order of the actions in the selected scene.

  4. In the Clear Trigger action menu, select the Trigger to be cleared.
  5. If there are more than one trigger in the selected scene, repeat the above steps for each trigger you need to clear.
  6. Save the project.

Updated May 24, 2019
Tags: