While working on my tank game, similar to Awesome Tanks, I encountered an issue with the AI tank shooting mechanic. I set up a separate timer for the AI tank to shoot a bullet, but when I attempt to run it, I receive an error stating that AItimer
is not defined in clearInterval(AItimer);
. I find this puzzling because the code is essentially the same as another timer that works perfectly fine.
function aiStartTimer() {
if (shoot == 0) {
//creates AItimer variable
AItimer = setInterval("aiFireBullet()", 100);
shoot = 1 * 1;
} else if (shoot == 1) {
clearInterval(AItimer);
shoot = 0 * 1;
}
}
For reference, you can view the code on JSFiddle