Forum Discussion

JudyNollet's avatar
JudyNollet
Super Hero
11 days ago

PRIMER: Trigger calculations in Storyline

How can you do the math in Storyline?

A Storyline trigger can only perform one of five actions on a number variable:

  • Set the variable
  • Subtract from the variable
  • Multiply the variable
  • Divide the variable
  • Add to the variable

 

There are 3 options for what number to use for Set, Subtract, Multiple, Divide, or Add:

  • Value: enter the number to use
  • Variable: select a numeric variable to use its value
  • Random: use a random number within a specified range

 

So what should you do if your project needs to perform a more complex calculation?

 

Perform each part of the equation in its own trigger.

 

Tips

Give meaningful names to your variables (as well as related objects). That will make it easier to program—and to troubleshoot.

A common mistake is performing the operation(s) on a variable without first resetting its value. That leads to unexpected results. To avoid that problem, always start a calculation with a trigger that sets the variable to the appropriate starting point, or that sets it to the first value used in the calculation.

Here’s how to simplify the programming if a complex calculation needs to occur when different items are clicked or updated.

  • Whenever the calculation needs to occur, use a trigger to show a layer.
  • Don’t put any objects on that layer.
  • Do put the calculation triggers on that layer and have them run when the layer’s timeline starts.
  • Adjust the Slide Layer Properties to “Reset to initial state.”
  • If the slide has other layers that might be showing, also adjust the Slide Layer Properties so showing the calculation layer doesn’t hide other layers.
  • Give the layer a very short timeline, and add a trigger that hides the layer when the timeline ends.

If you want to control what numbers a user enters and how to display results, you may need to add extra programming. In some cases, it might be doable with Storyline triggers that specify conditions. Or it might require JavaScript.

  • A numeric entry field accepts any number. By itself, it can’t control whether the entry is within a certain range, is a whole number, and/or contains a certain number of digits to the right of the decimal point.
  • You can’t specify the number of digits to the right of the decimal point in the calculation results. In other words, Storyline doesn’t show decimals beyond the final digit >0 in the calculation result. For example, Storyline displays a result of 2.50 as 2.5.
  • These issues have been discussed elsewhere in the Articulate community. Search for those posts. If you don’t find the answer you’re looking for, ask your question in a new discussion.

 

Here are some references that might be helpful:

 

No RepliesBe the first to reply