Forum Discussion
Variable Formatting
TaylerMarshall- the solution for this is as follows:
You need to define two variables, for example:
- SCORE type = number
- SCORE_DISPLAY type = text
SCORE will be used to track the users SCORE and SCORE_DISPLAY will be used to display the users SCORE with the appropriate formatting.
In order to set the SCORE_DISPLAY, you would use a simple piece of JavaScript. I have wrapped the script in a function called updateSCORE which we can call when we need to.
The window. before the function name makes it available to call outside of the slide, but you also need to put this function somewhere it will be included on the slides you need it to be available, for example, a template. In this example, I've just added it to the master template, and so this function will be available on every page in my module.
updateSCORE = function()
{
// Assign the Storyline Player to player
const player = GetPlayer();
// Assign the users SCORE to score (force to be a number)
const score = Number(player.GetVar("SCORE"));
// Convert the score to formatted string
const formattedNumber = score.toLocaleString();
// Set the SCORE_DISPLAY variable to the formattedNumber value
player.SetVar("SCORE_DISPLAY", formattedNumber);
}
I can then add the following function call to any trigger such as timeline start, button click, animation end etc.
window.updateSCORE();
In the example attached, the trigger is added to a button click after inputting the SCORE into the input field.