← BACK

Counters let you store numeric variable data during the execution of your project. For example, you can use counters to store the following types of data: 

  • Display data, for example, game level, score, currency.
  • Calculations, such as power values.
  • Scene ID references, which allow you to move to a specific scene from an unknown point. For details, see Transitions by Counter Value.

You can use and manipulate the stored counter values in any of the following ways:

  • Use actions to change counter values by performing math operations or simply resetting them.
  • Use Text Area elements and their actions to display counter values on the screen.
     

    Note: Counter values are invisible in the demo. To display them on the screen, you need to use counters with Text Area elements, for example, as described in Use Case 2 in Logic-Only Scenes.

  • Use counter values to move to specific scenes. For details, see Transitions by Counter Value.
  • Define conditional logic by setting counter conditionals for actions and transitions in your demo.
  • Use counters in Logic-only scenes to randomize transitions.

The sections below explain how to use counters and their actions. For an overall procedure and best practices, see Using Counters. For use case examples, see Logic-Only Scenes

Counter Actions

When working with counters, you may use the following actions. Depending on your design, you can add them though the Add an Action drop-down menu in the Events & Actions panel of a scene or Properties panel of a gesture.

  • Set Counter—allows you to set the counter to an explicit value.
  • Five counter actions with math operations—allow you to change counter values by adding, subtracting, dividing, multiplying, or changing counter value by modulo. For details on the operations and values, see Counter Action Menus.
  • Update Text with Counter—allows you to display counter values on the screen in the selected Text Area. You can also include additional text to be displayed with counter values on the screen. For text examples, see the Update Text with Counter action menu.

For example, in a project where the user needs to mine resources, you set a counter at the beginning of the project and set its value to 0. Later in the project, after the user starts mining, you increase the counter value to reflect the accumulated resource amount in a Logic-Only scene. At the end of the demo, you display the total resource count next to a resource icon (added separately as image layer) on the screen, for example, like this:

Below are the counter actions that you may add to the scenes in your demo to accomplish this. For a complete use case, see Use Case 2 in Logic-Only Scenes.

Conditional Logic in Actions and Transitions

In Studio, conditional statements determine whether an action or transition takes place, using the if/then logic with counter values in the following format:

If counter value is equal (greater than/less than/greater than or equal/less than or equal) to a specific value, then move to scene X (execute action Y).

If the condition specified in the counter if/then statement is true, the transition or action takes place. If not, nothing occurs, and you need to provide a default option.

Note: You can define conditional logic only at the scene level through the Events & Actions panel.

Transitions

In transitions, you can use counter conditionals to reuse scenes instead of creating multiple separate ones. For example, the following counter conditionals allow you to reuse a Game Over scene in addition to a regular transition to the scene at the end of the demo:

  • If max_level =1, then move to Game Over scene.
  • If level =10, then move to Game Over scene.
 

Note: If multiple conditional statements evaluate to true, Studio will randomize the transitions with equal probability.

Actions

In actions, you can use counter conditionals to display one of several media assets in the same scene. For example, the following counter conditionals allow you to  show one of two monsters while using the same combat logic for either of them:

  • If monster_id =1, then show Green Monster image element.
  • If monster_id =2, then show Black Monster image element.

For complete use case examples, see Logic-Only Scenes.

Using Counters

The overall process of using a counter to store and manipulate numeric values includes the following tasks. For use case examples illustrating the steps below, see Logic-Only Scenes.

 

Tip: It’s a best practice to plan and set all your counters in advance, at an earlier point in the demo, rather than in the scenes or gestures where you need to use them.

  1. Before you can use a counter, you need to create it and set its value first. To do this, add a Set Counter action in any appropriate scene at the beginning of the project as described below.
  2. Depending on your design, in the Events & Actions panel of all scenes where you need to manipulate the counter values, do what applies:
    • To set a new counter value, add a Set Counter action and enter the desired value.
    • To update the counter value using a math operation, add the appropriate Counter actions using the respective Counter Action Menus.
    • To display the counter value on the screen, add the Update Text with Counter action.
    • To use the counter value in transition conditionals, add the appropriate multiple transitions, add the counter conditionals to them, and, if needed, randomize the transitions
    • To use the counter value in action conditionals, add the appropriate multiple actions and add the counter conditionals to them.
  3. If replaying your demo restarts the experience, use the Set Counter actions to reset your counters at the end of the project. 

The sections below explain how to use the Set Counter action to add a counter and set or reset its value. For use case examples, see Logic-Only Scenes.

Create a Counter and Set Its Value
 

Tip: It’s a best practice to plan and set all your counters in advance, at an earlier point in the demo, rather than in the scenes or gestures where you need to use them.

  1. Depending on whether you want to set a counter for a scene or gesture, do one of the following:
    • Select the scene in the Scenes panel, and in the Events & Actions panel, click Add an Action, and select Set Counter.
    • Select the gesture in the Layers panel or on the canvas, and in its Properties panel, click Add an Action, and select Set Counter.
  2. Keep the default On Enter event or, if needed, click the At Time or On Exit event.
  3. In the displayed Set Counter action menu, in the Counter drop-down list, select New Counter.
  4. In the displayed dialog, enter a descriptive name for the counter without using special characters, capital letters, or spaces and click OK.

    The new counter is automatically selected in the Counter drop-down list.

  5. In the Value field, enter the initial value for the counter, such as an ID of an element you want to display randomly or 0 to start a count. For use case examples, see Logic-Only Scenes.
  6.  Save the project.

Reset a Counter
 

Tip: It’s a good practice to reset your counters in the end scenes of your project. You may skip this step, however, if you plan to allow the user to replay the demo, continuing the experience and keeping the score.

  1. In the Scenes panel, select the end scene or a scene after which you no longer need a counter.
  2. Go to Events & Actions, click Add an Action, and select Set Counter.
  3. Keeping the default On Enter event, in the displayed Set Counter action menu, in the Counter drop-down list, select the counter you want to reset.
  4. In the Value field, enter the appropriate value to reset the counter.
  5. Save the project.

Was this helpful?

Updated June 27, 2019
Tags: