Forum Discussion

ChristineSawh's avatar
ChristineSawh
Community Member
4 years ago

Using JavaScript with True/False Buttons

Hello! I am developing a menu selection course for students and I need assistance.  

Students will choose items to build their meal. Each item has a button associated with it. Each button is associated with (6) variables-- calories, fats, proteins, carbs/sugars, True/False, Text. When students 'checkout' they will be brought to a results slide which will breakdown the nutritional value of their 'meal' and list their selections.

On my results slide, all of the nutritional values of the selected items appear. I was also able to use JavaScript that I adapted from a previous storyline discussion thread to compile my list of selected items on the result slide:

var player = GetPlayer();
var List_Smash = player.GetVar("List_Smash");
var Bacon = player.GetVar("Bacon");
var Concate = List_Smash + Bacon;
player.SetVar("List_Smash",Concate);

For each item to appear in list format, I have the following triggers:

Trigger #1:  Set ItemT/FVariable to value True When the state of ItemButton is selected.

Trigger #2: Execute JavaScript (example above) When user clicks ItemButton, if ItemT/FVariable = value True

My only issue is, every time the associated button of an item is selected, SL adds the item to a list. I am unsure what I have to do in order to make sure only selected items are added to the list.

I am hoping this is possible! Thank you in advance for your assistance!

23 Replies