+ 4

Why clearInterval() doesn't work?

In research() function the agent is going through the maze and when he finds the goal it's supposed to stop the interval but it doesn't. No errors. Here. Line 46 if(element.hasClass("goal")) { clearInterval(interval); alert("Goal found +1") } The alert works. https://code.sololearn.com/WzbEOWsx7u9M Sometimes the agent takes some time to find the goal because it's going through the maze randomly. If the agent seems like it doesn't move it just went to the wall so the state remains the same.

9th Jun 2018, 11:29 PM
Toni Isotalo
Toni Isotalo - avatar
3 Réponses
+ 3
When you go into "trap" you call research for reply all again but you forget to clear interval before call research function... If you dont clear interval, a new call to reply get you in two different intervals (and more if other call happens) but interval value has only the last interval id setted (eg. when you go to goal your code will clear only last interval)... I hope that you have understanded me
9th Jun 2018, 11:47 PM
KrOW
KrOW - avatar
+ 3
Yes thanks..
9th Jun 2018, 11:49 PM
Toni Isotalo
Toni Isotalo - avatar
+ 1
👍👍👍
10th Jun 2018, 12:20 AM
KrOW
KrOW - avatar