+1 vote

how to make day and night cycle time?
for example i want 1 day = 16 minute, 8minute at day and 8 minute at night.
what should i do? how should i do?
should i use timer?

in Engine by (419 points)

1 Answer

+1 vote

The way I've done this..... I use a Singleton (Autoload) script and create my variables....


And my main game scene has a timer. On timeout... the seconds increment, which spill into the minutes, then hours, days, years, etc. I can get more detailed with this if you need.

You could make this increment to the next value anyway you want and also you can adjust the Timer interval so a second is however long you feel it should be.

by (133 points)

thanks, that would be nice if you can give more detail

I'll Pseudo-code it for you....

(so don't direct copy / paste - it wont work)

extends Node

var gameyear = -10000
var gamemonth = 1
var gameday = 1
var gameminute = 1

var gamesecond = 1

$Timer1 (enabled, internval say... 1 second to start, adjust as needed)

Connect the timer to it's method...
func onTimer1_timeout():

advance the second(s)

Singleton.gamesecond += 1

if Singleton.gamesecond >= 60:
Singleton.gamesecond = 0
Singleton.gameminute += 1

if Singleton.gameminute >= 60:
Singleton.gameminute = 0
Singleton.gamehour += 1

if Singleton.gamehour >= 24:
Singleton.gamehour = 0 #or 1? Depends how you want to id your hours)
Singleton.gameday += 1

if Singleton.gameday >= 30: #30 days in your game's month?
Singleton.gameday += 1
Singleton.gamemonth += 1

etc. etc. etc.

Let me know if you need more help.

thanks, i learn allot from your code,
i will :)

No worries, lots of folks have helped me on here.

I'm unavailable for a few days - till next week - but shout if you need more help with this, I will get back to you.

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.