• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Time module

przemek

New member
Joined
Sep 18, 2017
Messages
62
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.
 
as in actual time? 10:15 AM etc
or timing? 60FPS

Also which target platform?
 
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?
 
I would probably be able to make 1min = 1h, however I would need to know how to import real time
 
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)
         Add to User count
         LastMillisec = CurrentMillisec
 
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)
         Add to User count
         LastMillisec = CurrentMillisec

Hi, I have coppied the code but it doesnt like ":" and "to"
 
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:
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 :)
 
Back
Top Bottom