Performing arithmetic operations with variables

That's pretty grand sounding. What I want to do is gather variables on individual slides (CP1, BP1, TP1, CP2, BP2, TP2, and so on up to TP5) and then create a final scores to display that are the individual sums of  (CP1 to CP5), (BP1 to BP5), and (TP1 to TP5). How do I write a statement that does that on Slide 6? Thanks for your help!

10 Replies
Luke Benfield

I haven't tested this, but in theory this should work:

  1. Create a CPsum variable and make the initial value 0
  2. Create two buttons (or shapes) on slide 6 - one for Calculate, and one for Clear.
  3. Set up a trigger to set CPsum to zero when user clicks the Clear button.
  4. Set up the following triggers:
    • Adjust variable CPsum to Add Variable CP1 when user clicks the Calculate button.
    • Adjust variable CPsum to add variable CP2...
    • And so on for all the CP items.
  5. This should give you the sum of all the CP numbers.
  6. Replicate the same process for a BPsum variable and a TPsum variable.
  7. On slide 6, you'll want to create a shape or textbox that includes the %CPsum% reference (same format for the others) to display the final number on the sceen when you click the calculate button.

Hopefully that will help.

Alyssa Gomez

Hello Margaret! I wanted to point you to this tutorial video, which shows how to perform calculations in Storyline on a very basic level (you'll notice this video is for Storyline 1, but it also works for Storyline 2). I know you're set-up is going to be more complex than this, but this might give you a good base to build upon. 

Good luck with this project, and be sure to pop back in if you run into any roadblocks along the way!

Margaret Morse

Hello,

There's actually a glitch that I'll fix and repost soon. If you click on the buttons once to see subscores, it works, but if you click more than once, it keeps adding. I think a solution is to move the zeroing of the variables to the beginning of the previous slide and tie the calculation to the next button.

Margaret Morse

Here's a new version without the glitch. I've been trying to find a way to print the results with interpretation, but the way most cited in these discussions requires text variables, and what I've got are numbers. I've tried them as they are and I've tried to convert them without success. There's probably a way to do it in Javascript at the beginning of the target document, but I don't know how.