JavaScript Support

andrew-robertson
Community Member Posts: 321 ♦ Idol ♦
Hello there -
I have a fairly complex simulation that I am building out with the Lectora V21 application. I am stumped at one spot though.
I have a variable called _Lane2SearchDetails that is instantiated by Lectora and I either add or subtract values based on button clicks. There is a finite amount of information that can be assigned to that _Lane2SearchDetails (z1,z2,z3,z4,z5,z6).
Since this variable essentially is an array separated by commas, I would like to split the array using the str.split(',') function built into JavaScript. My best attempt is in a screenshot below.

Now, when I call that function I always get a minimum of one object in the array length, and it only goes up from there or down as a button is unclicked - but it never goes to 0 if there is no objects in the string or ~~~~null~~~~.
The flow occurs as listed below.
Button 1 Clicked (Enabled): Array length = 2, Array contents = z1,
Button 2 Clicked (Enabled): Array length = 3, Array contents = z1,z2,
Button 3 Clicked (Enabled): Array length = 4, Array contents = z1,z2,z3
Button 1 Clicked (Disabled): Array length = 3, Array contents = z2,z3,
Button 2 Clicked (Disabled): Array length = 2, Array contents = z3,
Button 3 Clicked (Disabled): Array length = 1, Array contents = ~~~null~~~
Unsure why it is giving me the array length of current length + 1.
Anything I am doing wrong (obviously I am)?
I have a fairly complex simulation that I am building out with the Lectora V21 application. I am stumped at one spot though.
I have a variable called _Lane2SearchDetails that is instantiated by Lectora and I either add or subtract values based on button clicks. There is a finite amount of information that can be assigned to that _Lane2SearchDetails (z1,z2,z3,z4,z5,z6).
Since this variable essentially is an array separated by commas, I would like to split the array using the str.split(',') function built into JavaScript. My best attempt is in a screenshot below.

Now, when I call that function I always get a minimum of one object in the array length, and it only goes up from there or down as a button is unclicked - but it never goes to 0 if there is no objects in the string or ~~~~null~~~~.
The flow occurs as listed below.
Button 1 Clicked (Enabled): Array length = 2, Array contents = z1,
Button 2 Clicked (Enabled): Array length = 3, Array contents = z1,z2,
Button 3 Clicked (Enabled): Array length = 4, Array contents = z1,z2,z3
Button 1 Clicked (Disabled): Array length = 3, Array contents = z2,z3,
Button 2 Clicked (Disabled): Array length = 2, Array contents = z3,
Button 3 Clicked (Disabled): Array length = 1, Array contents = ~~~null~~~
Unsure why it is giving me the array length of current length + 1.
Anything I am doing wrong (obviously I am)?
Andrew R.
Developing content since 2010 using a mixed bag of tools.
Developing content since 2010 using a mixed bag of tools.
Comments
-
What's wrong with the length?
When you split "z1," by the comma the resulting array should have two items: "z1" and "" (i.e. an empty item). The term "~~~null~~~" is a placeholder for "" (empty) that Lectora puts in. The moment you leave the Lectora context it is regular text, which makes it the first / only item of the array.
You might try to remove the last comma in the value before you turn it into an array:tempLaneZonesSearched = tempLaneZonesSearched.substring(0, tempLaneZonesSearched.length - 1);
This actually removes the last character, but that should usually be a comma in your case.
You can also remove the last item of the array:zoneArray.pop();
-
Categories
- 35.8K All Categories
- 109 ✫ Announcements
- 33.1K Lectora®
- 31.1K Lectora Discussions
- 28.9K Lectora Desktop
- 2K Lectora Online
- 2K Lectora Feature Requests
- 71 Lectora User Groups
- 36 Lectora Accessibility User Group (LAUG)
- 22 ELB Learning Content
- 22 ELB Learning Content Discussions
- 321 CenarioVR®
- 188 CenarioVR Discussions
- 133 CenarioVR Feature Requests
- 41 Rockstar Learning Platform®
- 38 Rockstar Learning Platform Discussions
- 108 CourseMill®
- 108 CourseMill Discussions
- 47 ReviewLink®
- 47 ReviewLink Discussions
- 7 The Training Arcade®
- 7 The Training Arcade Discussions
- 934 All Things eLearning
- 36 eLearning Development
- 546 Learning Management System (LMS) Integration
- 332 Web Accessibility
- 1.2K ♪ The Green Room
- 9 Additional Learning Products