DocumentInQuestion.png It has been suggested that this page's contents be merged with the page Setting the Time. You can discuss this on the page's talk page. (November 2017)

This is an easy tutorial on how to make a clock.

Note Note: The clock will tell the time set on your computer because it uses the "current ()" block.

Analogue Clock

Preparation

You will need to create 3 sprites: 2 long vertical lines and 1 short vertical line.

Note Note: If you make the lines vertical, you will save a lot of direction coding!
Note Warning: Set the costume center to any end of the lines otherwise the project won't work!

Coding

Second Hand

This is the script for the second hand:

when gf clicked
point in direction ((0) + ((current [second v]) * (6))) // x6 because 360/60=6
forever
wait (0.957) secs // If you wait for 1 second, then after 1 minute you will be 2 seconds behind!
turn cw (6) degrees
end

Minute Hand

This is the script for the minute hand:

when gf clicked
point in direction ((0) + ((current [minute v]) * (6)))
forever
wait until <([direction v] of [second hand v]) = [0]>
turn cw (6) degrees
wait (2) secs // So the minute hand won't turn 180 degrees!
end

Hour Hand

This is the script for the hour hand:

when gf clicked
point in direction (0 v)
turn cw (((current [hour v]) * (30)) + ((current [minute v]) / (2))) degrees // Calculations: 360/12=30 and 1/2=0.5;0.5*60=30
forever
wait until <([direction v] of [minute hand v]) = (([direction v] of [minute hand v]) + (6))
turn cw (0.5) degrees
wait (2) secs // So it wouldn't turn 15 degrees!

Digital Clock

Preparation

You will need to create only one variable named "Digital Time" or "Time".

Coding

24 Hour

This is the script on how to make a 24 hour digital clock:

when gf clicked
forever
set [Time v] to (join (current [hour v]) (join [ : ] (join (current [minute v]) (join [ : ] (current [second v])))))
end

12 Hour

This is the script for a 12 hour clock:

when gf clicked
forever
if <(current [hour v]) = [0]> then
set [Time v] to (join ((current [hour v]) + (12)) (join [ : ] (join (current [minute v]) (join [ : ] (join (current [second v]) [.am]))))
else
if <<(current [hour v]) > [0]> and <(current [hour v]) < [12]>> then
set [Time v] to (join (current [hour v]) (join [ : ] (join (current [minute v]) (join [ : ] (join (current [second v]) [.am]))))
else
if <(current [hour v]) = [12]> then
set [Time v] to (join (current [hour v]) (join [ : ] (join (current [minute v]) (join [ : ] (join (current [second v]) [.pm]))))
else
if <<(current [hour v]) > [12]> and <(current [hour v]) < [24]>> then
set [time v] to (join ((current [hour v]) - (12)) (join [ : ] (join (current [minute v]) (join [ : ] (join (current [second v]) [.am]))))
end
end
end
end
end

Examples

See Also