See also: Setting the Time

This is a tutorial on how to create a clock. This clock returns the player's time because this tutorial uses the current [ v] block, which is local.

Analogue Clock

Preparation

To start, create three Sprites: one for the hour hand, one for the minute hand, and one for the second hand.


Note Warning: Set the costume center to any end of the lines otherwise the project will not work.

Coding

Second Hand

This is the script for the second hand:

when gf clicked
forever
point in direction ((0) + ((current [second v]) * (6))) // x6 because 360/60=6.
end

Minute Hand

This is the script for the minute hand:

when gf clicked
forever
point in direction ((0) + ((current [minute v]) * (6)))
end

Hour Hand

This is the script for the hour hand:

when gf clicked
point in direction (0)
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 // This is so it would not turn 15 degrees.

Digital Clock

Preparation

Create only one variable named "Time" to start.

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
set [Time v] to (join ([abs v] of ((current [hour v]) - (12))) (join [ : ] (join (current [minute v]) (join [ : ] (current [second v])))))
end

Examples

See Also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.