Forum Discussion

Jenn-Barnabee's avatar
Jenn-Barnabee
Community Member
28 days ago
Solved

JavaScript Timer Question

Hello! I'm new to using JavaScript in Storyline. But after watching a Learning Dojo video and using Claude to help me put some code together, I was able to come up with the following code to use in a...
  • Nedim's avatar
    27 days ago

    Please check the attached Storyline file. Although I usually prefer playing games on their native platforms rather than within authoring tools, I took the time to create a simple solution that may help you track game time effectively.

    This setup includes a JavaScript timer that you can start, pause, and reset as needed. The main JavaScript code loads when the timeline starts. After that, you can control the timer by calling functions such as gameTimer.start(), gameTimer.pause(), and gameTimer.reset(). These functions can be triggered from buttons or other Storyline events.

    In addition to that, I created a timerId variable, which I believe aligns with your original approach based on your script. The code ensures that a new timerId is generated each time the user clicks the start button. When the reset function is called, the timerId is cleared as well, so that a new timerId will be created the next time the start button is pressed. 

    Example: