My issue revolves around intervals. Upon declaring a function with setInterval, I find that even after clearing the interval, the function continues to execute. Here is my code:
if (score == 1) {
leftBlinkTimer(0)
} else if (score == 0) {
leftBlinkTimer(1)
}
function leftBlinkTimer (state) {
let leftBlin = 0;
var timer;
if (state == 0) {
timer = setInterval(() => {
if (leftBlin == 0) {
const newData = {
stateLeftBlinker: 'rgba(255, 255, 255, 1)'
}
vm.changeMicro(newData)
leftBlin = 1;
} else if (leftBlin == 1) {
const newData = {
stateLeftBlinker: '#47EC5B'
}
vm.changeMicro(newData)
leftBlin = 0;
}
},600)
} else if (state == 1 || state == '1') {
clearInterval(timer)
}
Despite attempting to check the state in the timer and clear it, I've encountered issues where both 0 and 1 lead to the same state. Any assistance would be greatly appreciated! Thank you for your help :) I eagerly await a resolution