# 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

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.
• 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.

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!

Good morning (local time) and thanks! Have to deal with a different project today, but I'm looking forward to trying out your suggestion!

--mlm

Good morning Margaret! I'm in Texas, so it's still morning here. :)

That sounds great! Be sure to keep me updated, and I'd love to see the finished product, if you don't mind sharing it!

Thanks to both of you. I don't have an easy way to post the published version, but here's a file that seems to work. It's a silly inventory, but the one I wanted to make belongs to someone I'd need to ask permission to use.

Very cool, Margaret! Thanks for sharing that demo here!

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.

Thank you for the update, Margaret! I appreciate you taking the time to repost the file!

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.

Thanks for sharing your file! And since we don't support Javascript coding, hopefully some of our savvy community members can chime in and assist on that. :)