How to Create a Clock

Материал из Поле цифровой дидактики

Шаблон:See also This is a tutorial on how to create a clock. This clock returns the player's time because this tutorial uses the current 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.

Шаблон:Warning

Coding

Second Hand

This is the script for the second hand:

whenclickedforeverpointindirection0+currentsecond*6x6because360/60=6.end

Minute Hand

This is the script for the minute hand:

whenclickedforeverpointindirection0+currentminute*6end

Hour Hand

This is the script for the hour hand:

whenclickedpointindirection0turncurrenthour*30+currentminute/2degreesCalculations:360/12=30and1/2=0.5;0.5*60=30.foreverwaituntildirectionofminutehand=directionofminutehand+6turncw0.5degreeswait2secs

Digital Clock

Preparation

Create only one variable named "Digital Time" or "Time" to start.

Coding

24 Hour

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

whenclickedforeversetTimetojoincurrenthourjoin:joincurrentminutejoin:currentsecondend

12 Hour

This is the script for a 12 hour clock:

whenclickedforeverifcurrenthour=0thensetTimetojoincurrenthour+12join:joincurrentminutejoin:joincurrentsecond.amelseifcurrenthour>0andcurrenthour<12thensetTimetojoincurrenthourjoin:joincurrentminutejoin:joincurrentsecond.amelseifcurrenthour=12thensetTimetojoincurrenthourjoin:joincurrentminutejoin:joincurrentsecond.pmelseifcurrenthour>12andcurrenthour<24thensettimetojoincurrenthour-12join:joincurrentminutejoin:joincurrentsecond.amendendendendend

Examples

See Also

nl:Klok