# Time module

#### przemek

##### New member
Hello, I am trying to write a game but i need to use time in it. Could anyone help me out? Its for the school project.

#### Rich

##### Well-known member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
3rd Party Tool Dev
as in actual time? 10:15 AM etc
or timing? 60FPS

Also which target platform?

#### przemek

##### New member
Well, my plan is to make a resource based game. You would build buildings and collect lets say wood. When you have 1 lumberjack , you would get 5 wood per 1 in game hour. I want to make day cycle, where 1 hour in game would be 1 min in real life. Would you know how to do it?

#### przemek

##### New member
I would probably be able to make 1min = 1h, however I would need to know how to import real time

#### dawlane

##### Well-known member
CX Code Contributor
There are two ways to use time: Use GetDate; there are two version of this so see the documentation, or Millisecs. There is no module for time, only functions. For what you want to do you will need to use Millisecs and your own counting method. But you will be tied to the size of an integer data type.
The simplest method for Millisecs being:
Code:
``````Store current Millisec before game start
loop:
Get current Millisec
If CurrentMillsec>(LastMillisec+FRACTION_OF_TIME_TO_ELAPSE)
LastMillisec = CurrentMillisec``````

#### przemek

##### New member
There are two ways to use time: Use GetDate; there are two version of this so see the documentation, or Millisecs. There is no module for time, only functions. For what you want to do you will need to use Millisecs and your own counting method. But you will be tied to the size of an integer data type.
The simplest method for Millisecs being:
Code:
``````Store current Millisec before game start
loop:
Get current Millisec
If CurrentMillsec>(LastMillisec+FRACTION_OF_TIME_TO_ELAPSE)
LastMillisec = CurrentMillisec``````

Hi, I have coppied the code but it doesnt like ":" and "to"

#### dawlane

##### Well-known member
CX Code Contributor
That's not Ceberus code. It's pseudo code meant as a guide.
A real example:
Code:
``````Import mojo

Class CGame Extends App
Field lastTick:Int
Field secs:Int
Field min:Int
Field hrs:Int

Method OnCreate:Int()
lastTick = Millisecs()
Return 0
End Method

Method OnUpdate:Int()
Local tick:Int = Millisecs()
If tick>=(lastTick+1000)
lastTick = tick
secs += 1
Endif

If secs > 59 Then
secs = 0
min +=1
If min > 59 Then
min = 0
hrs +=1
If hrs > 23 Then hrs = 0
Endif
Endif

Return 0
End Method

Method OnRender:Int()
Cls
DrawText("Seconds: "+secs, 100, 100)
DrawText("Minutes: "+min, 100, 112)
DrawText("Hours: "+hrs, 100, 124)
Return 0
End Method
End Class

Function Main:Int()
New CGame()
Return 0
End Function``````

Last edited:

#### przemek

##### New member
That's not Ceberus code. It's pseudo code meant as a guide.
A real example:
Code:
``````Import mojo

Class CGame Extends App
Field lastTick:Int
Field secs:Int
Field min:Int
Field hrs:Int

Method OnCreate:Int()
lastTick = Millisecs()
Return 0
End Method

Method OnUpdate:Int()
Local tick:Int = Millisecs()
If tick>=(lastTick+1000)
lastTick = tick
secs += 1
Endif

If secs > 59 Then
secs = 0
min +=1
If min > 59 Then
min = 0
hrs +=1
If hrs > 23 Then hrs = 0
Endif
Endif

Return 0
End Method

Method OnRender:Int()
Cls
DrawText("Seconds: "+secs, 100, 100)
DrawText("Minutes: "+min, 100, 112)
DrawText("Hours: "+hrs, 100, 124)
Return 0
End Method
End Class

Function Main:Int()
New CGame()
Return 0
End Function``````

Oh... didnt know soz. But thank you for the code and pseudocode you are very helpful to me