Forum Discussion
Variable Persistence Issue in Articulate Storyline
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
- MohamadhuAsarud8 months agoCommunity 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
andwindow.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!