Add/Subtract Checked/Unchecked Button Text Variables from Multiple Slides to Results Slide

Dec 06, 2021


I am putting together a 'Design your Meal' exercise.  Students will choose to a restaurant to build their meal. So far, I have buttons associated with each menu item. Each button is associated with (4) variables-- calories, fats, proteins, carbs/sugars. When students 'checkout' they will be brought to a results slide which will breakdown the nutritional of their 'meal.' 

On the results slide, I also want all of the items that were picked in the previous slides to be listed under 'PICKS' in order for students to see what they picked and answer subsequent questions after. E.g. If someone selects, components of a burger (black bean patty, LTO, classic bun), chocolate milkshake, and fruit cup, I would like these (5) items listed on the results slide.

Reviewing multiple discussion threads, I haven't been able to figure out how to accomplish this. I tried to make text variables for each ingredient and link that to its corresponding button however, I am unable to make them do what I want. I am hoping this is possible!

Thank you in advance. I've learned soo much from these thread discussions and tutorials.

8 Replies
Richard Watson


Here is one way to approach it using variables but it can become cumbersome if you have a lot of options. I'm sure someone will have additional suggestions for you as well that might be more efficient. This is something that I put together in about 5 minutes between client calls.

I've attached the .story file for you. Basically, when you make your selections, it is setting the associated variable to TRUE (from a default value of False) when the user clicks Submit Your Answers.  On the final results page, the user's selection are automatically changed to a state of Selected if the value of the associated variable is TRUE. I also placed a transparent rectangle over the final selections to keep the user from being able to click on them.

Christine Sawh

Hello Richard:

Thanks for taking the time to review my request! I am hoping to only have the selected items from the (5) menu slides listed on the results page.  So, using your screenshot above, under the 'Your Selections' section, only Classic Bun, Ground Beef Patty, and American Cheese would be listed. 

Is there a way that this could be accomplished?

Richard Watson

I would agree that JavaScript would be the better method. As Walt stated, you could use states but that leaves a blank area (e.g, when it was hidden). Sorry for the slow response. I didn’t receive a notification that you had responded.  I don’t have a ton of experience with JavaScript but perhaps one of the others here does and will be able to provide you with the script to make that happen.

Walt Hamilton


Here's a script that I have used. The slides are proprietary, but you may use the script.  Instructions are in Bold.

var player = GetPlayer();
var correct =[];
var inCorrect =[];
var selections =[];
var j=1;
var k=1;
var NOP = ["","Jaw Thrust maneuver", "Oropharyngeal airway", "Nasopharyngeal airway", "King (multi-lumen) airway", "Laryngeal Mask Airway (LMA)", "Endotracheal tube", "Cricothyroidotomy"]

//NOP stands for "Name of Procedure". They are used here as the answers that print on the slide if selected.

selections[1] = player.GetVar("JawThrust");
selections[2] = player.GetVar("Oro");
selections[3] = player.GetVar("Naso");
selections[4] = player.GetVar("King");
selections[5] = player.GetVar("LMA");
selections[6] = player.GetVar("ET_Tube");
selections[7] = player.GetVar("Crico");

These variables that are gotten are in SL. They are T/F, set to false initially, and set to true by SL if they are selected. They correspond to the names of the procedures.

for(i = 1; i < 8; i++){
if (selections[i] == true) {
correct[j] = NOP [i];
} else {
inCorrect[k] = NOP[i];

The correct and inCorrect arrays are for the js, and are populated according to the selection of the variable values gotten from SL (true or false). Then they are returned to SL, and placed into the SL text variables (Correct1, Correct2 ... through 9, and InCorrect1, InCorrect2 ... through 9). The procedures that are selected (true) have their names placed in the Correct variables, and the others are placed in InCorrect variables.

for(i = 1; i < 8; i++){
if (correct[i] != null) {player.SetVar("Correct" + i, correct[i]);}
if (inCorrect[i] != null) {player.SetVar("InCorrect" + i, inCorrect[i]);}
player.SetVar("correctAnswers", j-1);

The Correct and InCorrect variables are returned to SL, along with correctAnswers (a numeric variable in SL) which represents how many answers were selected.

This is the page in SL that displays them. Correct and InCorrect variables that don't have values don't display,

This may get you started.

Christine Sawh

Hello Walt:

Thank you for providing the steps. I have to admit, I am an absolute novice and I cannot figure out the purpose for some of the lines in your javascript and fear that it may take a bit to explain them to me.

I did complete a few steps based on your and Richard's previous responses.  At this point, I'm not certain if I am placing these triggers on the incorrect slide layers because my javascript is not working.

I have (5) slides that I am trying to compile a list from on the final slide. I am working on just one of the slides to see if I can get this to work.

I've created the following variables to accomplish this task:

  1. Text Variable: "VariableName" with a Default Value of "Dessert Name"
  2. Text Variable: "List" No Default Value
  3. T/F Variable: "VariableName" with a Default Value of False  

On Dessert slide, I have (2) layers-- layer 1 contains all of the buttons and text and will execute layer 2, the calculation tab when the user clicks a button on layer 2.

  • Each dessert button is set to T/F (default= false) until a user clicks on the button. This button is also tied to another trigger calculating nutritional values of the item-- this part works.
  • On layer 2, the calculate layer, I created a trigger for each button following this format:  Set "T/FVariableName" to value "True" When the "timeline starts" on "this layer" If the state of "ButtonName" is "Selected".

Then, on the final slide where I want all of the selected items to be listed, I have an "Execute Javascript" for all buttons. The formula is:

var player = GetPlayer();
var List = player.GetVar("List");
var ChocMilkshake_Text = player.GetVar("Chocolate Milkshake");
var Concate = List + Chocolate Milkshake;

Then, I inserted a reference %List%  in hopes that the selected buttons trigger the text to show up in list format on the final slide.

When I publish, it doesn't work. I'm missing something...