Forum Discussion
Adding or Sum of Variables. Possible?
I'm making a simulation type game in storyline which has branching to different paths based on 3 different choices.
I made a variable called "Money from Company A", and i want this to be updated based on a given choice.
So let's say for simplicity:
Choice 1 - 10$
Choice 2 - 5 $
Choice 3 - 1$
If we have 5 questions in total, the maximum score should be 50$, and the minimum 5$, with a bunch of other possibilties.
The problem i was encountering was when a user is on the screen, and selects choice 1 then changes their mind to choice 2, the triggers i have set still add the points up. So a user can get more than 10$ on a question if they keep switching between choice 1 and choice 2.
I overcame this by making the variable change only when the user clicks the "submit" button at the end, so they have left the slide, and cannot change their answer.
All good up until this point.
But I was wondering whether or not I could calculate the sum of different variables, if I decided to add another company into my scenario? So in the results slide, I could show a total of the money earned from the two companies.
is there a function that could do %Money from A% + %Money from B% ? Or Sum(Variable1, Variable2)?
The only solution I have now, is to display the two variables in the results slide, and have the person add it up manually.
Deniz
- PhilMayorSuper Hero
This shows how to add variables together, this way you dont destroy any oft the values
- mimileeCommunity Member
Hi Phil. Many thanks for this fab piece of tutorial on how to add variables together. You have saved me lots of time and frustration.
- EricaBerghout-1Community Member
Hi Phil. after 7 years, your post saved my day! Thanks!
- PhilMayorSuper Hero
:-)
- AshleyKirstein-Community Member
So helpful! Thanks, Phil.
- DANIELGIMNESSCommunity Member
Can you add to the feature list for the next revision of storyline, the ability to add variables together like this: resultNum==variable1+variable2
The current method is tedious.
- susanchengCommunity Member
Hi Daniel,
You can add two or more variables by using javascript. I made a sample here.
- DANIELGIMNESSCommunity Member
Thanks Susan!
- GerryWasilukCommunity Member
- chrisKeightCommunity Member
I sorta done a work around for this, I made a bar where it totals up your drinks. http://www.alcoholandyouni.com/unitchecker/story_html5.html I used the scores from the variables to change another text box with the score? It even can connect to a database with your results. I'm actually making another tonight and looked here to see if there is a better way?
Hi Rozbud,
This discussion is a bit older, and Javascript isn't something I can help with - but can you share a bit more about what you'd like to see for variable features I'd love to get those ideas in the hands of our product team!
- WaltHamiltonSuper Hero
Mary,
Phil's example adds three variables (Money1, Money2, and Money3) together. To add more, just duplicate either of the circled triggers, and use the appropriate variable.
- GregWilliams-ebCommunity Member
Even 11 years later this gift keeps on giving. Thank you Phil! Bless you sir.
- PhilMayorSuper Hero
You can add it up using triggers, sometimes helps to have an intermediary variable.
You will need more than one trigger to do this
- DenizOlcayCommunity Member
So,do I do it like it is below? Add Money to Money 2 when the timeline starts?
But then i can't show the original "Money" amount in the slide.
Can you show me how to do an intermediary variable?
Ideally, I'd like to be able to show on the reuslts slide:
Money
Money 2
Money 3
---------------------------
(Money + Money 2+ Money 3)
- DenizOlcayCommunity Member
You really are a super hero!