Discuss Scratch

Superbman19
Scratcher
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
Scratcher
40 posts

How to create stopwatch?

when green flag clicked
set [timer v] to [0]
repeat until <(stopwatch) = [false]>
wait (.1) secs
change [timer v] by (0.1)

end
Then make a way to change stopwatch between true and false.
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
Scratcher
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
Scratcher
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/
digthebone
Scratcher
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
Scratcher
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
Scratcher
1000+ posts

How to create stopwatch?

Psiborg wrote:

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.
This ^^

Don't try to use wait blocks, they are hugely inaccurate.
Superbman19
Scratcher
17 posts

How to create stopwatch?

Ben02045 wrote:

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
Scratcher
36 posts

How to create stopwatch?

Superbman19 wrote:

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)
(seconds)
(minutes)
(time)
Then, add this script:
when green flag clicked
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
Then, add this:
when green flag clicked
forever
set [ time] to [(join [(minutes)] (join [:] (join [(seconds)] (join [.] [(milliseconds)])))) ]

end
Hope it was helpful!

Last edited by programma07 (Feb. 2, 2016 00:33:51)

Harakou
Scratcher
1000+ posts

How to create stopwatch?

programma07 wrote:

Superbman19 wrote:

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)
(seconds)
(minutes)
(time)
Then, add this script:
when green flag clicked
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
Then, add this:
when green flag clicked
forever
set [ time] to [(join [(minutes)] (join [:] (join [(seconds)] (join [.] [(milliseconds)])))) ]

end
Hope it was helpful!
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!

Powered by DjangoBB