Bring an array into Storyline

Hi Heros...

I want to bring an array into Storyline using SetVar function. 

var arr = ["Joe", "John", "Car", "Hat"], i;
console.log(arr);
for( i=0; i<arr.length; i++ )
{
console.log(arr[i]);
var player = GetPlayer();
player.SetVar("reza",arr);

}

Here is the result of the code above:

Joe, John, Car, Hat

But I want something like a list like this :

Joe

John

Car

Hat

Note: Number of Array values are different.

Any Suggestions?

 

 

 
3 Replies
OWEN HOLT

If you anticipate using each item separately later in your course, you could also assign each array member to its own variable in SL.  By placing each in its own variable, you can display them anyway that you want in Storyline.
Also, passing through the array for each iteration of "i" is probably unnecessary for your code once you declare the array.

var arr = ["Joe", "John", "Car", "Hat"];

var player = GetPlayer();
player.SetVar("reza",arr);
player.SetVar("first",arr[0]);
player.SetVar("second",arr[1]);
player.SetVar("third",arr[2]);
player.SetVar("fourth",arr[3]);