Bring an array into Storyline
Jan 19, 2019
By
Sara Ree
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
Hi Sara,
There are likely any number of ways to do what you're asking. One way is to convert the array to a comma-delimited string and then replace the commas with line feeds (\n). Publish the attached Storyline 360 file to see if it's accomplishing your needs.
Hi Steve
Thank You! It is nicely answered :)
Please Accept my best regards.
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]);
This discussion is closed. You can start a new discussion or contact Articulate Support.