GetTime

From Game Editor

Jump to: navigation, search
stTime getTime();

getTime returns a struct that's variables contain information about the date and time. This function and the stTime struct allow you to access information about the system time (uses 24 hour time), so you can create dynamic aspects of your game based on time, seasons, and similar.

stTime's Variables

  • sec: Holds the system's seconds count. (0-59)
  • min: Holds the system's minutes count. (0-59)
  • hour: Holds the system's hour count. (0-23)
  • mday: Holds the day of the month. (1-31)
  • mon: Holds the month of the year. (1-12)
  • year: Holds the current year.
  • wday: Holds the day of the week. (0-6 [Sunday=0])
  • yday: Holds the day of the year. (0-365)
  • sec_utc: Number of seconds elapsed since midnight (00:00:00), January 1, 1970 (coordinated universal time)


Using getTime()

Using a struct like getTime uses the dot operand, much like accessing another actor's actor variables. For example: timeDisplay (text actor) -> Draw Actor -> Script Editor

stTime t = getTime();
sprintf(text, "%d:%02d:%02d", t.hour, t.min, t.sec);


Application Example:

One use of getTime is to allow you to change the time of day according to the player's system clock. So, you can darken the screen as the day progresses. To do this, create a screen overlay (a completely black actor the size of the screen). Parent it to the screen, and reduce its transparency to 0.75 so you can see under it.

lightOverlay -> Draw Actor -> Script Editor

stTime t = getTime();

transp=abs((t.hour-16)*60.0+t.min-660.0)/(660.0)*0.5;

This will set the transparency of the overlay to a max of 0.5 at the 12 in the morning, and 0.0 in the afternoon. to adjust the max darkness, simply adjust the ending 0.5 in the equation. You can also do the reverse with a white filter, which would allow you to also incorporate seasonal light, and give you the ability to alter the rgb values to make sunsets and similar.