Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to create stopwatch?
- Superbman19
-
17 posts
How to create stopwatch?
How do you create a stopwatch that features minutes, seconds, and milliseconds? It should be one variable (like 0:0,00). I know it's possible as I saw it in another project, but I can't figure out which one it was.
- Ben02045
-
40 posts
How to create stopwatch?
when green flag clickedThen make a way to change stopwatch between true and false.
set [timer v] to [0]
repeat until <(stopwatch) = [false]>
wait (.1) secs
change [timer v] by (0.1)
end
Just realised that you want it to display minutes too. I'll see what I can do.
Last edited by Ben02045 (Feb. 26, 2015 19:28:48)
- BannedForever451
-
100+ posts
How to create stopwatch?
The only way I know how to is to make a sprite for hours, minutes, seconds, and miliseconds and have however many costumes (60 for minute, second, and milisecond) like PullJosh did Here.
Last edited by BannedForever451 (Feb. 26, 2015 23:43:36)
- Ben02045
-
40 posts
How to create stopwatch?
I spent some time to make a project for this. Feel free to use it for anything you want and message me if you have any additional questions.
http://scratch.mit.edu/projects/49819346/
http://scratch.mit.edu/projects/49819346/
- digthebone
-
500+ posts
How to create stopwatch?
when green flag clicked
set [stopwatch v] to [0]
repeat until <<mouse down?> and <touching [mousepointer v] ?> >
change [stopwatch v] by (1)
wait (1) secs
end
Last edited by digthebone (Feb. 27, 2015 14:23:00)
- Psiborg
-
500+ posts
How to create stopwatch?
You'd be better off using the timer block under the sensing category. Reset timer to start the stopwatch. Have a variable to hold the elapsed time and set this to timer * 1000 within your main loop. This gives you the number of milliseconds. Then just do a bit of maths to extract the minutes, seconds and milliseconds.
- MegaApuTurkUltra
-
1000+ posts
How to create stopwatch?
This ^^ You'd be better off using the timer block under the sensing category. Reset timer to start the stopwatch. Have a variable to hold the elapsed time and set this to timer * 1000 within your main loop. This gives you the number of milliseconds. Then just do a bit of maths to extract the minutes, seconds and milliseconds.
Don't try to use wait blocks, they are hugely inaccurate.
- Superbman19
-
17 posts
How to create stopwatch?
I spent some time to make a project for this. Feel free to use it for anything you want and message me if you have any additional questions.
http://scratch.mit.edu/projects/49819346/
Thanks! This worked pretty well, just had to change a couple of things.
- programma07
-
36 posts
How to create stopwatch?
How do you create a stopwatch that features minutes, seconds, and milliseconds? It should be one variable (like 0:0,00). I know it's possible as I saw it in another project, but I can't figure out which one it was.
Do something like this:
Create 4 variables:
(milliseconds)Then, add this script:
(seconds)
(minutes)
(time)
when green flag clickedThen, add this:
forever
wait (0.1) secs
change [milliseconds] by (1)
if <[milliseconds] = [ 10]> then
set [milliseconds] to [ 0]
if <[seconds] = [60]> then
set [ seconds] to [ 0]
change [ minutes] by (1)
end
end
end
when green flag clickedHope it was helpful!
forever
set [ time] to [(join [(minutes)] (join [:] (join [(seconds)] (join [.] [(milliseconds)])))) ]
end




Last edited by programma07 (Feb. 2, 2016 00:33:51)
- Harakou
-
1000+ posts
How to create stopwatch?
Thanks for your input! However, please note that this thread is a year old and has already been resolved. Please read the whole thread before posting and don't bump ones that are no longer relevant. Thanks!How do you create a stopwatch that features minutes, seconds, and milliseconds? It should be one variable (like 0:0,00). I know it's possible as I saw it in another project, but I can't figure out which one it was.
Do something like this:
Create 4 variables:(milliseconds)Then, add this script:
(seconds)
(minutes)
(time)when green flag clickedThen, add this:
forever
wait (0.1) secs
change [milliseconds] by (1)
if <[milliseconds] = [ 10]> then
set [milliseconds] to [ 0]
if <[seconds] = [60]> then
set [ seconds] to [ 0]
change [ minutes] by (1)
end
end
endwhen green flag clickedHope it was helpful!
forever
set [ time] to [(join [(minutes)] (join [:] (join [(seconds)] (join [.] [(milliseconds)])))) ]
end![]()
![]()
![]()
- Discussion Forums
- » Help with Scripts
-
» How to create stopwatch?