Forum Discussion
JavaScript for getting today's month
- 2 months ago
Hi DwayneDush if you define a variable in Storyline called currentMonth. Make it a number variable (it will initialise as zero).
You would then place a variable change trigger on that variable, which will then determine what happens based on the value of that variable, for example, if the variable changes and it's value is "1" i.e January, you could then show layer "January", if the value is "2" then show "February" etc.
You then just need to execute some JavaScript on the timeline start trigger that will set the Storyline variable:
// Get the Storyline player API const player = GetPlayer(); // Get the current month const currentMonth = new Date().getMonth() + 1; // Adding 1 because getMonth() returns 0-based index // Set the Storyline variable player.SetVar("currentMonth",currentMonth);
Hi DwayneDush if you define a variable in Storyline called currentMonth. Make it a number variable (it will initialise as zero).
You would then place a variable change trigger on that variable, which will then determine what happens based on the value of that variable, for example, if the variable changes and it's value is "1" i.e January, you could then show layer "January", if the value is "2" then show "February" etc.
You then just need to execute some JavaScript on the timeline start trigger that will set the Storyline variable:
// Get the Storyline player API
const player = GetPlayer();
// Get the current month
const currentMonth = new Date().getMonth() + 1; // Adding 1 because getMonth() returns 0-based index
// Set the Storyline variable
player.SetVar("currentMonth",currentMonth);