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);
Javascript does not run in preview mode. One needs to publish the course (Web version is fine), and try check out the javascript. Yes, a bit painful
- DwayneDush2 months agoCommunity Member
Thank you for pointing that out! What I had might have worked but I went with the code JS provided. And thanks to you, I went straight to the publish to test it out. Good call!
- PhilMayor2 months agoSuper Hero
Javascript will now run in preview, has done for months. If it doesn't run check the console (available in preview)