Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Simple count down timer
- Andrew_1225
-
New Scratcher
6 posts
Simple count down timer
So um I'm trying to make a count-down timer that can accurately decrease at a rate of .01 seconds but when I run what I believe should do that the countdown is drastically longer than it should be and I don't know why. Can anyone help me figure out whats wrong with it?
when green flag clicked
set [ time] to [10]
broadcast [ go]
when I receive [ go]
repeat until <(time) = [0]>
wait (.01) secs
change [ time] by (-.01)
end
- deck26
-
Scratcher
1000+ posts
Simple count down timer
The wait n secs block is not accurate enough - the loop also takes time to run. You want to use the built-in timer variable for this as it is accurate. If you want a countdown reset the timer and, in a loop, set your variable to 10 - timer. Never check for timer = value though as you may not get an exact match. For example if you check for timer=10 and at teh times you check it it is at 9.99 and 10.01 you won't get an exact match.
- ayyyyes10135
-
Scratcher
100+ posts
Simple count down timer
when green flag clicked
forever
change [ timer] by (-1)
wait (1) secs
end
- Andrew_1225
-
New Scratcher
6 posts
Simple count down timer
The wait n secs block is not accurate enough - the loop also takes time to run. You want to use the built-in timer variable for this as it is accurate. If you want a countdown reset the timer and, in a loop, set your variable to 10 - timer. Never check for timer = value though as you may not get an exact match. For example if you check for timer=10 and at teh times you check it it is at 9.99 and 10.01 you won't get an exact match.
Thank you, this is exactly what I needed
- Discussion Forums
- » Help with Scripts
-
» Simple count down timer




