Forum Discussion

DwayneDush's avatar
DwayneDush
Community Member
2 months ago
Solved

JavaScript for getting today's month

I would like to create a page in Storyline where the system identifies the current month.  Then based on that month, the page will display a unique image (i.e. the layer specific to that month).  The...
  • SamHill's avatar
    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);