Trouble getting score variable to increase

Dec 04, 2019

Hi everyone!  I'm trying to build a simple game in which learners select potential classroom hazards to achieve a max score.  I have a trigger to add 1 to the score variable value when a correct answer is selected and subtract 1 when it isn't (otherwise the score would go up every time they clicked on the same answer).  Oddly, the subtract trigger is working but not the add... resulting in no change to the score if the learner selects the correct answer and then a negative score if they dis-select it!  What am I doing wrong? 

5 Replies
Wendy Farmer

Hi Betty

see if the following is what you are after.  I always use variables when I have a select/deselect interaction.

I wasn't sure if you were deducting -1 for book, ball and table which is how I have it set up - if that's not what you want just delete those three triggers under each object.

Hope this helps

Betty Steel

Edit: Nevermind!  I looked harder and figured out what you did with the toggles!  Makes so much sense- thank you! 

 

Thank you SO much!  I deleted the variable triggers for the incorrect answers but otherwise this is exactly what I was going for.  I see that you added a toggle variable trigger to the choices and that's what made the difference, but I don't quite understand why?  Maybe I don't need to understand, but I can't wrap my head around why the add and subtract triggers alone won't enough, let alone why only the subtract trigger was working but not the add?  I super appreciate your help with the file, so thank you again.  I just want to understand the mechanics so I can apply them going forward. 

Wendy Farmer

Hi Betty

the toggle variable reacts when the user clicks to select/deselect the object.  From experience - this can happen sometimes more than one or twice so I like to control exactly what is going to happen by using a toggle variable for each object.

The toggle variable starts out with a default value of false.  When the user clicks the object (state=selected), the variable changes to true, when they click it again (state=not selected or normal), the variable changes back to false. I am then able to use the toggle variable in my triggers to make sure the score is accurate.

I find if you have the score variable changing based on their clicks and using only state of selected for some reason the score doesn't always keep up with the adding and subtracting.

I'm sure other users may do something different and SL is very flexible in the way you can code things - this is my way so I hope this helps you.

This discussion is closed. You can start a new discussion or contact Articulate Support.