#hi, I have a problem with my timer
13 messages · Page 1 of 1 (latest)
I forgot to say:
Active is used to say if the timer is paused or not
sessionL and breakL is the length of each timer
session is used to say if the session timer is being used
timer is set to breakL and sessionL based on second but it is formatted later on the code
(there is a posibility that the code is fine, and mabye the environment is the problem)
This snippet is incomplete, so I don't know what you are doing with the value of "type", but the part that you showed doesn't make use of its value at all. If it actually gets used somewhere, you will need to fix the logic of how it is being set. The only place where it is set is inside an if statement that checkss if prev is equal to 0. That means the type can only change when timer is 0, and I don't see any code that stops it from becoming a negative number.
Also, it is common to update once per second instead of 10 times per second. I am not sure if you realize that setInterval uses milliseconds instead of centiseconds, or if you really want the higher frequency.
that was only for faster tests, I didn't want to wait 60s every time I wanted to test my code, and the timer never hits zero, the problem is the switch, the type of the timer is used as a label above the actual timer in the render method, after the first switch (session to break) it doesn't switch session and just runs break timer in an infinite loop
Why do you believe the timer never reaches 0? Is that your expectation based on your understanding of the code or have you tested it? If it never reaches 0, how is the type ever being changed? Do you have critical code changing this state that you did not share? In the code that you shared, this state can only change when timer reaches 0.
yes it does reach zero what are you talking about?
every time in the loop there is a setTimer with a prev and if timer reaches 0 it switches the timer and if not it will return the prev -1 meaning 1 second has passed
"and the timer never hits zero"
You said it doesn't. Now you say it does.