0 votes

So i want to make a day and night cycle that goes from am to pm, or at the very least 0 to 23, but i'm completely new to godot and when i look online, all i see are real time clocks which are neat but not what i needed, any tips?

in Engine by (12 points)

1 Answer

0 votes

I hope you don't take it personally but you sound pretty young. I recommend if you are as young as I think you are and don't understand my link that you ask your math teach about remainder/modulo as that is the answer to your problem.

You need to use modulus operator.

So if you want a 24 hour day.

0 % 24 = 0
1 % 24 = 1
2 % 24 = 2
23$24 = 23
24 % 24 = 0
25 % 24 = 1
26 % 24 = 2

func update_time():
      time = (time + 1)  % 24

What the above code will do is that anytime you reach 24, time will loop back to 0 without needing any logic.

if you don't what to use modulo, use an if statement

func update_time():
      if time == 24:
             time = 0
            time = time + 1
by (98 points)

Thanks! and it's fine, didn't realized i sounded young, never heard of remainder/modulo, school never taught that. didn't think math would come in when it came to making a clock XD

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.