How to make a clock: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
Created page with '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 …'
 
Added a tutorial on how to add an in-game clock.
Line 29: Line 29:
</pre>
</pre>


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 user exactly at midnight for one minute. Try it out and see what it is. :)
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. :)


<pre>
<pre>

Revision as of 13:56, 2 March 2009

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 there in-game clock time by changing their desktop time.