Adding Variables together mathematically
Aug 27, 2015
Hi,
I am currently running into an issue where I am attempting to add together the "ScorePoints" variables of 6 quizzes to another number variable that I created called "IntPoints." For simplification purposes I set each quiz value to 1, so each one answer that is answered correctly should get 1 point, and if its answered incorrectly they get 0. so I added a trigger for each "ScorePoints" result from the quiz to add its value to the "IntPoints" variable that I created, and set to 0 at the start of the timeline. So I expected that since these variables were all "numbers" and not "text" variables when I added one variable to another it would compute as a number. So I added into the slide %IntPoints%, expecting its outcome to be "6" on the page. Instead I get "111111". I get a 1 "added" to the end of it, as if its adding it like a string, and not computing it like a number.
I do feel that I have a way around this, but just doing some logic to add a "value" of "1" to the "IntPoints" variable based on some logic, but I am a bit confused by why my scenario outlined above is not working for me. I assumed this would give me a "6" adding all of these variables together since they are all "number" variable types. I am attaching the images of my variables and output for reference. Thanks!
6 Replies
I think you will need to pipe that out to JavaScript and have it do the maths and push it back.
But since you don't have JavaScript the Results variables... you will need to create some new SL vars and set their values. In SL you will do something like:
set score1 to Results.ScorePoints
set score2 to Results2.ScorePoints
Than in a JS trigger:
Keep in mind that was off the top of my head and I didnt test the code. But the logic should be sound.
You can do this without Java. I would create a separate numerical variable that starts at 0, for each result slide. Have a trigger on the success layer for each result. Then have your IntPoints trigger at the end. See the attached example
Hi Eric! Looks like you are getting some great assistance here :)
Thank you very much James and Cary both. Cary your example worked flawlessly. And I am able to add the new values together up without any issue. I guess ultimately I still don't quite understand why I was unable to use the values from the Results.Scorepoints variables since those are also "numerical", but this works exactly how I need it. Thanks again.
Thanks for the update Eric :)
I'm not sure either Eric, but as long as it works now I'm happy.
This discussion is closed. You can start a new discussion or contact Articulate Support.