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

  • ChristineSawh's avatar
    ChristineSawh
    Community Member

    Hello Math:

    This is my 1st experience building in Storyline so, I will definitely check out the other editors you referenced.

    I used the array you provided for the item names-- it worked perfectly.

    I then used the array you provided for the nutritional values and ran into trouble. The array removes duplicates and I don't need this feature when it comes to the nutritional values. For example:

    Water = 0 cal, 0 protein, 0 fat, 0 carbs

    Soda = 245 cal, 0 protein, 0 fat, 66 carbs

    Lemonade = 260 cal, 0 protein, 0 fat, 70 carbs

    All of these have the same values for protein and fat so, I would like these values listed 3 times in the protein and fat columns when the items are selected.

    Currently, if these items are selected together, then, protein and fat columns do not have '0' listed 3 times, its left blank. 

    I'm unsure if there is a work around for this.  Hope this makes sense!

    ~ Christine

     

    • MathNotermans-9's avatar
      MathNotermans-9
      Community Member

      For sure there is... let me jump on it...
      I guess... as the values are always the same for the ingredients... its a table or multidimensional array from which you select the appropriate values. I make a sample of it.

  • ChristineSawh's avatar
    ChristineSawh
    Community Member

    Thank you for taking this on. I'm bumbling through this but, learning soo much!

  • Although this works..
    https://360.articulate.com/review/content/5a979e06-302f-4ba4-9c7f-dcd53e8af038/review

    Im not completly happy with it... as the alignment of the values of the ingredients is tough to get right... as its pure text.

    I wanted to use a multidimensional Array, but for a quick solution i used a simple array and pass along the index ( arrays are always zero-based ) from Storyline.
    If this works for you its good...if you too don't like the alignment and rather have more textboxes so you can finetune alignment in Storyline... i fix it when i got some time...

  • ChristineSawh's avatar
    ChristineSawh
    Community Member

    Hello Math!

    Thank you again for your assistance. I adapted your code for all of my slides and then noticed something odd. So, I checked out your linked file and noticed it as well.

     If I choose any items out of order, the 1st item in the list that shows us is 'Chocolate Milkshake' as it is the 1st item in the ListArray and so forth . Here are 2 examples below:

    Do you have a suggestion?

    Thank you again for your assistance!

    ~ Christine

    • MathNotermans-9's avatar
      MathNotermans-9
      Community Member

      Mmm...gonna check and fix that...also had an idea tonight about aligment and layout.

  • And here that version is. Splitted up the array into separate ones for calories, protein...etc. and using those now.
    https://360.articulate.com/review/content/923fee11-6b92-4251-85a1-259c4462382a/review

    One thing to watch with this approach is the length of your items name / textfield. If its too short it will wrap to a next line...and when that doesnot happen with your nutrition values...well then it rapidly becomes hard to decipher for your student.

    Have a nice day,
    Math

  • ChristineSawh's avatar
    ChristineSawh
    Community Member

    Math:

    I just incorporated your array into my SL and finalized it for review; it worked for all 52 items! I am indebted to you for all of your assistance and cannot convey how thankful I am. 

    Everyone's tips provided a lot of education and demonstrated the multiple ways I could build future courses. For this reason, I look forward to learning and creating more in SL.

    Thanks again!

    ~ Christine

  • No problem Christine. Love to help. Just shout out in the forum whenever you need any help.
    Math