How to make a clock

From EDukeWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

In this tutorial we will create an in-game clock that displays the users current desktop time in the top right hand corner of the screen.

We will need the following gamevar definitions:

gamevar sec                      0 1
gamevar min                      0 1
gamevar hour                     0 1
gamevar mday                     0 1
gamevar mon                      0 1
gamevar year                     0 1
gamevar wday                     0 1
gamevar yday                     0 1

Next, the code itself which must be used in an event because digitalnumberz and rotatesprite only work during display events. We will be using EVENT_DISPLAYREST in this case.

onevent EVENT_DISPLAYREST

gettimedate sec min hour mday mon year wday yday
ifvarl hour 20 ifvarg hour 9 { digitalnumberz 2992 285 16 hour 0 0 0 0 0 xdim ydim 65536 }
ifvarg hour 19 { digitalnumberz 2992 282 16 hour 0 0 0 0 0 xdim ydim 65536 }
ifvarl hour 10 { digitalnumberz 2992 288 16 hour 0 0 0 0 0 xdim ydim 65536 rotatesprite 269 16 65536 0 2992 0 0 0 0 0 xdim ydim }
ifvarg min 9 { digitalnumberz 2992 308 16 min 0 0 0 0 0 xdim ydim 65536 }
ifvarl min 10 { digitalnumberz 2992 315 16 min 0 0 0 0 0 xdim ydim 65536 rotatesprite 296 16 65536 0 2992 0 0 0 0 0 xdim ydim }

endevent

The uses for this code are just about endless, it could be used to make certain events trigger at a certain time during the day. For example, if we add the following code to our example it will display a special message for the end user exactly at midnight for one minute. Try it out and see what it is. :)

ifvare hour 0 ifvare min 0 { quote 28 }

It should be noted that the end user can change their in-game clock time by changing their desktop time.