+ 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.
3 Antworten
+ 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
+ 3
Yes thanks..
+ 1
👍👍👍