SetTimeout and SetInterval not working

Joined
Feb 12, 2025
Messages
1
Reaction score
0
13.png


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.

14.png


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:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,241
Messages
2,571,219
Members
47,851
Latest member
TheoChestn

Latest Threads

Top