how to make day and night cycle time?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By potatobanana

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?

:bust_in_silhouette: Reply From: mattkw80

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.

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

potatobanana | 2021-08-18 16:12

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 _on_Timer1_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.

mattkw80 | 2021-08-18 16:32

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

potatobanana | 2021-08-20 14:16

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.

mattkw80 | 2021-08-20 17:11