JS Functions in Articulate Storyline 2

I have a course where I have a role selection and I need to pull random scenes based on a learners role from a collection of 9 based on their level etc.

The code works, as I have tested it but it keeps coming up with the following error in the console: 

Error in user.js 5mMNiYIhP5A TypeError: roleSelection.splice is not a function
at Script1 (user.js:31)
at ExecuteScript (user.js:6)
at Slide.Element.runAction (player_compiled.js:277)
at TimelineAction.performAction (player_compiled.js:1058)
at TimelineAction.<anonymous> (player_compiled.js:1074)
at Function.each (player_compiled.js:21)
at StoryEvent.triggerEvent (player_compiled.js:1074)
at StoryEvent.<anonymous> (player_compiled.js:262)
at Function.each (player_compiled.js:21)
at Slide.Element.handleEvent (player_compiled.js:262)


Looks like it has something to do with the splice() function. I'm stumped as to how to get around this splice() function issue. Does Articulate just not allow splice()?

JS code is below:

// Get the player
var player = GetPlayer();

// Define Roles
var role1 = ['1','2','4','5','6','8','9'];
var role2 = ['1','2','3','4','5','9'];
var role3 = ['1','2','3','4','5','6','8','9'];
var role4 = ['1','2','4','7','8','9'];
var role5 = ['1','2','4','8','9'];
var role6 = ['1','2','3','4','5','6','7','8','9'];
var role7 = ['1','2','3','5','8','9'];

// Get roleSelection Storyline variable
var roleSelection = player.GetVar("RoleSelection");

var random1 = roleSelection[Math.floor(Math.random() * roleSelection.length)];
var random1Index = roleSelection.indexOf(random1);
if (random1Index > -1) {
roleSelection.splice(random1Index, 1);
var random2 = roleSelection[Math.floor(Math.random() * roleSelection.length)];
var random2Index = roleSelection.indexOf(random2);
if (random2Index > -1) {
roleSelection.splice(random2Index, 1);
var random3 = roleSelection[Math.floor(Math.random() * roleSelection.length)];
console.log(random1 + ", " + random2 + ", " + random3);


2 Replies