Forum Discussion
Using JavaScript with True/False Buttons
Status Update: Feeling accomplished and defeated. I fear that my 1st build in SL is a lot bigger than I anticipated.
Math's arrays worked perfectly for the names of the selected items. However, along with the name of the items, I would like the nutritional values of the selected items to also be listed. This is where I ran into trouble.
In the example below, Soda and Lemonade both have 0 protein and 0 fats. Instead of these numbers showing up in both columns in list form, they are hidden. I know its because this section of Math's script:
if(findEntryIndex(listArray,newValue)== -1){listArray.push(newValue);}else{removeEntry(listArray,findEntryIndex(listArray,newValue));}
Is there a way that I can adjust Math's array to list the duplicate values of selected items?
If not, I think the next step may be for me to do as Phil shared:
...if you wanted to fix what you have I would have added the triggers to a layer and added a trigger to reset concate variable and show the layer each time you click a checkbox...
I am just unsure how to go about this since I have (4) variable for each food item.
Walt, thank you for the outline! If there isn't a fix for me at this point, I'll rebuild this whole course per your direction and see where I end up.
Thank you again in advance!
~ Christine
- MathNotermans-94 years agoCommunity Member
Im not 100% sure what your problem is Christine, but i do think its as easy as creating separate arrays for the nutritional values... eg. create a list/array for Proteins and push/remove/read the values from there....
Quickly added it as sample here.../*So now we need to find and delete the selected value from the Storyline variable*/var player = GetPlayer();var listArray=[];var proteinArray= [];var StorylineList = player.GetVar("listArray");var StorylineProteinList = player.GetVar("proteinListArray");var newValue = player.GetVar("newValue");var newProteinValue = player.GetVar("newProteinValue");if(StorylineList!=""){listArray = StorylineList.split(",");}if(StorylineProteinList!=""){proteinArray = StorylineProteinList.split(",");}if(findEntryIndex(listArray,newValue)== -1){listArray.push(newValue);}else{removeEntry(listArray,findEntryIndex(listArray,newValue));}if(findEntryIndex(proteinArray,newProteinValue)== -1){proteinArray.push(newProteinValue);}else{removeEntry(proteinArray,findEntryIndex(proteinArray,newProteinValue));}var cleanArray = uniq(listArray);var cleanProteinArray = uniq(proteinArray);player.SetVar("proteinListArray",cleanProteinArray.toString());player.SetVar("listArray",cleanArray.toString());player.SetVar("displayList",cleanArray.join("<br />"));player.SetVar("proteinDisplayList",cleanProteinArray.join("<br />"));function uniq(a) {return Array.from(new Set(a));}function findEntryIndex(_array,_string){return _array.indexOf(_string);}function removeEntry(_array,_index){return _array.splice(_index,1);}Do use a proper Javascript enabled texteditor. Although Storyline's editor is improved now, it still is quite inferior to editors like Sublime Text and Brackets.
Related Content
- 11 months ago