Adding Variables together mathematically


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
onEnterFrame (James Kingsley)

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:

var p = GetPlayer()
var jsIntPoints = p.GetVar('score1') + p.GetVar('score2')
p.SetVar('IntPoints', jsIntPoints)

Keep in mind that was off the top of my head and I didnt test the code. But the logic should be sound. 



Eric Allen

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.