Javascripting Question: Adding a "0" to the front of variable in Storyline 360
Feb 05, 2017
Looking for some help on the following.
I have a dial (SL variable name: DialMin) that is set to show values from 1 - 59 in increments of 1.
I would like to have the values from 1-9, show up as 01,02,03....09 when I show the variable onscreen using the %DialMin%.
I've pulled some javascript from the forums here but I'm not sure of what I need to do to accomplish my goal. Any help would be appreciated!
=====
//bring in the DialMin variable from Storyline
var player = GetPlayer();
var numberFromStoryline = player.GetVar("DialMin");
//Convert number from DialMin variable into a string
var convertedToString = numberFromStoryline;
if (convertedToString <10) {
convertedToString ="0" + convertedToString;
}
//set values for Storyline
player.SetVar("DialMin", convertedToString);
Thanks again for the help on this one!
Richard
2 Replies
I only had a quick glance at the script. It looks to me there is a type mismatch, e.g. you are trying to execute a math operation on a string variable (convertedToString <10). But I thought there is no need to use JS here, you can adjust the variable display with two triggers as per the attached.
Michael,
A case of "overthinking" it! I appreciate your quick response. I was able to create a single state for "LowValues" and just keep the Normal state for use with numbers 10 and up.
A much easier solution indeed.
Richard
This discussion is closed. You can start a new discussion or contact Articulate Support.