Forum Discussion

MohamadhuAsarud's avatar
MohamadhuAsarud
Community Member
10 months ago

Variable Persistence Issue in Articulate Storyline

I'm currently working on a project in Articulate Storyline and have encountered a persistent issue related to variable handling. I've extensively used JavaScript to manage a variable called "TimeDisplay_1," associated with a textbox on Slide 1.

The issue arises when navigating between slides. Upon returning to Slide 1, the textbox displays two values: the old value when leaving the slide and the initial value (00:00) that continues incrementally. Despite attempting to reset the variable on timeline start and clear the old entry using JavaScript triggers, the problem persists.

I have explored various solutions, including resetting the variable explicitly with JavaScript, but to no avail. The objective is to prevent the accumulation of old values and ensure the textbox starts fresh on each visit to Slide 1.

If anyone has encountered a similar challenge or has insights into resolving this issue, I would greatly appreciate your expertise. Additionally, any guidance on best practices for variable management in Articulate Storyline would be invaluable.

 

  • Hi Mohamadhu, are you able to share a stripped down example. I'd be happy to take a look at this for you.

  • Hi Mohamadhu, it is because the intervals you run, continue to run in the background. When you navigate to a new slide in SL, it isn't unloading the page, and so any intervals you start, will continue to run. If you continue to go back and forward in the slides, you will just keep initialising new intervals. The way to fix this issue is to assign the intervals to global variables. You can then run clearInterval() on them to stop them running. I assign the variable to the window object to ensure if is global and can be accessed by the script, as the script you define in SL get's wrapped in a JavaScript function. See the attached file for the solution.

    Not, I am using a different variable to store the interval on slide one and two:

    window.globalIntervalA
    window.globalIntervalB

    If it is not important for the timer to keep going when the user leave the slide it is running on, you could simply use the same variable, ensuring you clear the current interval each time before a new one is assigned to it. This will ensure that memory isn't unnecessarily used up, which can be a problem if intervals aren't stopped when they don't need to be running.

    Cheers,
    Sam

    • MohamadhuAsarud's avatar
      MohamadhuAsarud
      Community Member

      Hi Sam,

      Thank you so much for your insightful response and the attached solution file. I truly appreciate your explanation regarding the intervals running in the background and the recommendation to assign them to global variables. Your suggestion to use different variables for intervals on each slide and utilizing window.globalIntervalA and window.globalIntervalB makes perfect sense.

      I'll implement these changes and run tests to ensure the issue is resolved. Your additional tip about clearing intervals when not needed is also noted, and I'll make sure to incorporate that into my approach.

      Once again, thank you for your prompt and clear guidance. It's immensely helpful!