The SetTimeout() timer and SetInterval() alike that has lightning flash every now and then is not working. Here is where the animate() function happens and where the timeout is called and it doesn't work.
Here is where the lightning effect is coded and it works successfully if there is no timeout.
EDIT:
If I use SetTimeout or SetInterval, and I put a console.log('Hello world!')
Then I notice in the console that the message in fact appears after set number of seconds, and then a number on the left of 'Hello world!' keeps increasing rapidly with no end.
Except if I use a doOnce variable, then it only fires once.
However, the lightning effect still doesn't happen.
Interestingly, it enters and exits the function but just doesn't do the stuff.
Now it seems that it does in fact enter all parts of the lightning function but I can't see the alpha updating visually.
So all of the variables are updating but I just can't see the changes visually.
I got it working. I simply moved the ctx.fillStyle and ctx.fillRect in front of the setInterval function.
Last edited: