# Question about Javascript?

**URL:** <https://talk.atomisystems.com/t/question-about-javascript/7257>\
**Category:** Support Questions\
**Created:** [March 13, 2023, 1:32am UTC](https://talk.atomisystems.com/t/question-about-javascript/7257 "2023-03-13T01:32:48Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oskar\_Muller](https://talk.atomisystems.com/user_avatar/talk.atomisystems.com/oskar_muller/32/4364_2.png) [@Oskar\_Muller](https://talk.atomisystems.com/u/Oskar_Muller)\
**Post date:** [March 13, 2023, 1:32am UTC](https://talk.atomisystems.com/t/question-about-javascript/7257/1 "2023-03-13T01:32:48Z")

</div>

Hello,  
in the game catchingBirds there is the javascript “function timelineEventHandler(doc, e)”. For a project I’m looking for a way to stop this timer with a mouse click and then end it. I would be very grateful for useful tips, since I’ve been spending some time with it, unfortunately without any results.  
greeting  
Oscar

---

<div class="post-metadata">

**Author:** ![ToanLS](https://talk.atomisystems.com/letter_avatar_proxy/v4/letter/t/46a35a/32.png) [@ToanLS](https://talk.atomisystems.com/u/ToanLS)\
**Post date:** [March 13, 2023, 1:57am UTC](https://talk.atomisystems.com/t/question-about-javascript/7257/2 "2023-03-13T01:57:12Z")

</div>

Hi Oskar,

You can store the timer id returned by `setInterval` in the `doc` global object, and pass it to `clearInterval` function in your mouse click event.

```javascript
// start the timer in a function / event handler
doc.myTimerId = setInterval(yourFunction, yourInterval);

// stop the timer in another function / event handler
if (doc.myTimerId) {
  clearInterval(doc.myTimerId);
  delete doc.myTimerId;
}

```

Regards

---

<div class="post-metadata">

**Author:** ![Oskar\_Muller](https://talk.atomisystems.com/user_avatar/talk.atomisystems.com/oskar_muller/32/4364_2.png) [@Oskar\_Muller](https://talk.atomisystems.com/u/Oskar_Muller)\
**Post date:** [March 14, 2023, 12:13pm UTC](https://talk.atomisystems.com/t/question-about-javascript/7257/3 "2023-03-14T12:13:18Z")

</div>

Hi,  
Great, that was the impetus I was looking for. Sometimes you can no longer see the forest in front of many trees. Thanks.  
greeting  
Oscar

---

<div class="post-metadata">

**Author:** ![Oskar\_Muller](https://talk.atomisystems.com/user_avatar/talk.atomisystems.com/oskar_muller/32/4364_2.png) [@Oskar\_Muller](https://talk.atomisystems.com/u/Oskar_Muller)\
**Post date:** [March 30, 2023, 10:27am UTC](https://talk.atomisystems.com/t/question-about-javascript/7257/4 "2023-03-30T10:27:09Z")

</div>

Hello Toan Le,

I have another question about my problem, with the command “clearInterval(timeinterval);”  
I can “pause” the timer, so the timer display stops( as desired) and  
can call the next scene. But if I stay in the scene, I noticed,  
that the timer display is stopped, but the timer itself continues to run in the background?  
I tried it with the command “delete Interval(timeinterval);”, but this shows no effect?  
What am I doing wrong?

thanks  
Oskar

Translated with [DeepL Translate: The world's most accurate translator](http://www.DeepL.com/Translator) (free version)

---

<div class="post-metadata">

**Author:** ![ToanLS](https://talk.atomisystems.com/letter_avatar_proxy/v4/letter/t/46a35a/32.png) [@ToanLS](https://talk.atomisystems.com/u/ToanLS)\
**Post date:** [March 30, 2023, 10:39am UTC](https://talk.atomisystems.com/t/question-about-javascript/7257/5 "2023-03-30T10:39:41Z")

</div>

Hi Oskar,

`clearInterval` will cancel the timer completely.  
I’m not sure why you think that the timer still runs in the background.  
Please describe your problem in more detail and share your project package (File \> Save As \> Package) so that I can help.

Regards

---

<div class="post-metadata">

**Author:** ![Oskar\_Muller](https://talk.atomisystems.com/user_avatar/talk.atomisystems.com/oskar_muller/32/4364_2.png) [@Oskar\_Muller](https://talk.atomisystems.com/u/Oskar_Muller)\
**Post date:** [March 30, 2023, 12:07pm UTC](https://talk.atomisystems.com/t/question-about-javascript/7257/6 "2023-03-30T12:07:14Z")

</div>

Hello Toan Le,  
thank you for your time. In the example you will see what I mean. 1. the timer is started(blue Button), runs down and triggers an action (the lower green one).  
2. the timer is stopped(red Button), triggers an action (the upper yellow one).  
But now you can see, after the remaining seconds, that the lower green action is executed anyway. So I assume that the timer is still running?  
thank you  
Oskar  
[mytimer.saolapack](https://talk.atomisystems.com/uploads/short-url/n7B5whzSoeA46agTwUcLZU5C3uu.saolapack) (2.7 KB)

---

<div class="post-metadata">

**Author:** ![ToanLS](https://talk.atomisystems.com/letter_avatar_proxy/v4/letter/t/46a35a/32.png) [@ToanLS](https://talk.atomisystems.com/u/ToanLS)\
**Post date:** [March 31, 2023, 2:58am UTC](https://talk.atomisystems.com/t/question-about-javascript/7257/7 "2023-03-31T02:58:24Z")

</div>

Hi,

You didn’t use `clearTimeout(timeout_timer_id)` to clear the timeout timer that starts the timeline after 10s so it still runs.

However, you don’t need to use JavaScript in your project, using predefined actions are enough.  
Please see your project fixed: [mytimer\_fixed.saolapack](https://talk.atomisystems.com/uploads/short-url/ww1Rn0T2EUTt2qYLPBs5AKjypvI.saolapack) (3.0 KB)

Regards

---

<div class="post-metadata">

**Author:** ![Oskar\_Muller](https://talk.atomisystems.com/user_avatar/talk.atomisystems.com/oskar_muller/32/4364_2.png) [@Oskar\_Muller](https://talk.atomisystems.com/u/Oskar_Muller)\
**Post date:** [March 31, 2023, 9:59am UTC](https://talk.atomisystems.com/t/question-about-javascript/7257/8 "2023-03-31T09:59:54Z")

</div>

> [@Oskar\_Muller](#):
>
> Toan Le,

Hello Toan Le,

yes, that is also a possibility, simple and easy, I don’t know why I haven’t  
I have not yet thought of it myself. Maybe you could answer me one more question about Java, what exactly is the “timer\_id”? Could you give me an example?

Thanks for your time  
Oskar

---

<div class="post-metadata">

**Author:** ![ToanLS](https://talk.atomisystems.com/letter_avatar_proxy/v4/letter/t/46a35a/32.png) [@ToanLS](https://talk.atomisystems.com/u/ToanLS)\
**Post date:** [April 3, 2023, 2:26am UTC](https://talk.atomisystems.com/t/question-about-javascript/7257/9 "2023-04-03T02:26:38Z")

</div>

Hi Oskar,

Timer id is the return value when calling a timer function (`setTimeout` or `setInterval`).  
You’ll use it to stop the timer (with `clearTimeout` or `clearInterval`, respectively).  
You can see a tutorial for beginners about these functions here: [JavaScript Timing Events](https://www.w3schools.com/js/js_timing.asp)

Regards

---

<div class="post-metadata">

**Author:** ![Oskar\_Muller](https://talk.atomisystems.com/user_avatar/talk.atomisystems.com/oskar_muller/32/4364_2.png) [@Oskar\_Muller](https://talk.atomisystems.com/u/Oskar_Muller)\
**Post date:** [April 3, 2023, 9:21am UTC](https://talk.atomisystems.com/t/question-about-javascript/7257/10 "2023-04-03T09:21:47Z")

</div>

Hi Toan Le,

thanks for the link…

Oskar
