Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Help with countdown timer
- mrcreatorluigi
-
Scratcher
1000+ posts
Help with countdown timer
https://turbowarp.org/616443012
So I'm trying to make a countdown timer in this project until it reaches January 5, 2022. But a common problem that's occurring is when a certain part of the timer counts to zero and loops backward, it sets it to something like 99, and then if it changes again, it becomes 88, etc. It's hard to explain, but it's the best I can do.
So I'm trying to make a countdown timer in this project until it reaches January 5, 2022. But a common problem that's occurring is when a certain part of the timer counts to zero and loops backward, it sets it to something like 99, and then if it changes again, it becomes 88, etc. It's hard to explain, but it's the best I can do.
Last edited by mrcreatorluigi (Dec. 14, 2021 04:12:58)
- Burnt-Butter-Toast
-
Scratcher
78 posts
Help with countdown timer
Well, I was thinking of using the timer block but I couldn't think of anything. but I have a different idea.
when green flag clickedAnd in a separate blockchain,
set [Time v] to [10]
forever
wait (0.01) secs
change [Time v] by (-0.01)
end
forever
if <<(Time) = [0]> or <(Time) < [0]>> then
set [Time v] to [0]
end
end
- gor-dee
-
Scratcher
1000+ posts
Help with countdown timer
Use
(days since 2000)have a look at this thread https://scratch.mit.edu/discuss/topic/563289/
- kuswerdz
-
Scratcher
100+ posts
Help with countdown timer
I'm not really good with this kind of stuff, and you seem to be an advanced Scratched, but my best guess is that if you're using a timer variable, you don't have code to loop a place value properly. If I could take a look at the code, I might be able to help.
- deck26
-
Scratcher
1000+ posts
Help with countdown timer
Your problem is that if, for example, 60 - current second returns a single digit number then the costume for the first digit of the two-digit display is set to the first digit of the seconds value. So instead of 59 you get 99, instead of 58 you get 88 and so on. Simplify the code for the first digit since if 60-seconds is less than 10 you just want to display 0 for the first digit. In fact the first digit's costume number is just floor ((60-seconds)/10) - no need for anything fancier than that.
The second digit is actually just (60 - seconds) mod 10 so again no need for if/else blocks.
The second digit is actually just (60 - seconds) mod 10 so again no need for if/else blocks.
Last edited by deck26 (Dec. 14, 2021 15:10:49)
- mrcreatorluigi
-
Scratcher
1000+ posts
Help with countdown timer
Your problem is that if, for example, 60 - current second returns a single digit number then the costume for the first digit of the two-digit display is set to the first digit of the seconds value. So instead of 59 you get 99, instead of 58 you get 88 and so on. Simplify the code for the first digit since if 60-seconds is less than 10 you just want to display 0 for the first digit. In fact the first digit's costume number is just floor ((60-seconds)/10) - no need for anything fancier than that.Thanks! It seems to be fixed now
The second digit is actually just (60 - seconds) mod 10 so again no need for if/else blocks.

- Discussion Forums
- » Help with Scripts
-
» Help with countdown timer




