Difference between revisions of "Function for Time of Day"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Daemonjax
(casting Time to an int is faster than calling Math.Floor())
imported>Daemonjax
(Undo revision 29046 by Daemonjax (talk) testing my conclusion ingame seems impossible)
Line 11: Line 11:


float Time = Utility.GetCurrentGameTime()
float Time = Utility.GetCurrentGameTime()
Time -= (Time as int) ; Remove "previous in-game days passed" bit, and faster than using Math.Floor()
Time -= Math.Floor(Time) ; Remove "previous in-game days passed" bit
Time *= 24 ; Convert from fraction of a day to number of hours
Time *= 24 ; Convert from fraction of a day to number of hours
Return Time
Return Time

Revision as of 02:31, 23 February 2012


The global function GetCurrentGameTime can be used to return the number of in-game days passed, including the fraction of the current day that has passed.

This function removes the portion of GetCurrentGameTime's return value that returns to previous in-game days, then converts the remaining portion to hours.


float Function GetCurrentHourOfDay() 

	float Time = Utility.GetCurrentGameTime()
	Time -= Math.Floor(Time) ; Remove "previous in-game days passed" bit
	Time *= 24 ; Convert from fraction of a day to number of hours
	Return Time

EndFunction