Un-pausing day/night cycle when re-entering World Map instead of restarting it

Hi all. I'm working on implementing a day/night cycle in my game, with specific functionality: I want the day/night cycle to only run on the world map, and pause on whatever phase of the cycle it's on when you enter towns/dungeons/etc.

I've found several helpful threads here to get me pretty far toward this goal. I've managed to get the day night cycle to only run on the world map and pause when you enter a town/dungeon. The problem, however, is that when I return to the world map, the day/night cycle starts over (I have it set to begin at the "Daytime" setting) rather than continuing from whichever day/night phase you were on while you were in the town/dungeon.

In other words, every time I return to the world map, it's daytime, even if the town I just left was on the "Night" phase.

See below for a look at how I have things currently set up. I'd love any advice from the RPGMakers here who are smarter than me and can help me figure out how to solve this last little problem!

(Or if this is already addressed by an existing plugin, happy to go that route, too.)

Thank you!

1. I have four Common Events to cycle through the four day/night phases and handle the screen tinting:

Dawn Common Event
Tint Screen: (34, -34, -68, 170)
Wait: 300 frames
Control Switches: #0002 ItIsDawn = OFF
Control Switches: #0003 ItIsDaytime = ON

Daytime Common Event
Tint Screen: (0, 0, 0, 0)
Wait: 999 frames
Control Switches: #0003 ItIsDaytime = OFF
Control Switches: #0004 ItIsDusk = ON

Dusk Common Event
Tint Screen: (68, -34, -34, 0)
Wait: 300 frames
Control Switches: #0004 ItIsDusk = OFF
Control Switches: #0005 ItIsNight = ON

Night Common Event
Tint Screen: (-68, -68, 0, 68)
Wait: 999 frames
Control Switches: #0005 ItIsNight = OFF
Control Switches: #0002 ItIsDawn = ON


2. On the world map, I have a Parallel Event to start the Common Event cycle (starting with "Daytime"):

Control Switches: #0003 ItIsDaytime = ON
Erase Event


3. On the town/dungeon maps, I have a Parallel Event to pause the Common Event cycle on whichever part of the cycle it was on when you exited the world map:

If: ItIsDawn is ON
Control Switches: #0002 ItIsDawn is OFF

Else

If: ItIsDaytime is ON
Control Switches: #0003 ItIsDaytime is OFF

Else

If: ItIsDusk is ON
Control Switches: #0004 ItIsDusk is OFF

Else

If: ItIsNight is ON
Control Switches: #0005 ItIsNight is OFF

End
First thing that comes to mind is do you have an initial event that kicks this off the first time you enter the world map?
If you do, that event is likely restarting every time and causing your issues.

Recoding the event(s) is a whole other matter, but if this way works for you, it's cool.
(I'd use one variable to note the day phases and another to note the time passing.)
Hi there! Yes, this event on the world map kicks off the day/night cycle:

Control Switches: #0003 ItIsDaytime = ON
Erase Event

I'm sure I've coded this whole system inefficiently, but for better or worse, it's gotten me 90% of the way there; it's just getting it to stay on whichever day/night phase it was on when you exited the town/dungeon that's got me hung up. I wonder if I need to add some conditional statements to that kickoff event above to check what cycle it's on (when you exit the town/dungeon). Will try that next.

First thing that comes to mind is do you have an initial event that kicks this off the first time you enter the world map?
If you do, that event is likely restarting every time and causing your issues.

Recoding the event(s) is a whole other matter, but if this way works for you, it's cool.
(I'd use one variable to note the day phases and another to note the time passing.)
you need to count the time in a variable, and only a few waits in the parallel that counts it up.
something like

wait(10)
control variable timecount+=1
if timecount > 60
>> timehour +=1
>> timecount=0
if indungeon = true
>> exit event processing
if timehour = 5
>> tintscreen
if timehour = 9
>> tintscreen
if timehour = 18
>> tintscreen
if timehour = 20
>> tintscreen
if timehour = 24
>> timehour = 0

place the commands in a parallel common event and have it always running
and inside, you turn on the switch "indungeon" to prevent tinting without stopping time
I threw together a quick common event to handle this.
You can view them to see pretty much how you do it with 1 Switch and 2 Variables.
DayCycle1.png
DayCycle2.png


You'd just need to turn on/off the common event when entering/leaving the world map.
So ANY TIME you switch, make sure the transfer event turns the switch OFF if leaving the World Map and ON if going back to it.
(The idea of having a starting event can help here, but even then, there are better ways around this.)

Note that the variables move in reverse order.

Trust the process. It works.

Let me know if you need anything more regarding setting this up.
One thing to note is that the cycle continues as long as the PCs are on the world map including during conversations and other events.
If you need the cycle to stop on the world map, you'll need to do a few more steps.
This is great, Maliki79! It's working well, and much cleaner than my version. My only hitch is that the first time you're on the map, it tints immediately to the "Dusk" phase of the cycle, which makes sense, but I'd like it to start out at the "Day" phase.

Thoughts on how to set up the initial event so that the map starts at "Daytime" the first time you're on it? Currently the event just switches the DayCycleCounter to ON.

you need to count the time in a variable, and only a few waits in the parallel that counts it up.
something like

wait(10)
control variable timecount+=1
if timecount > 60
>> timehour +=1
>> timecount=0
if indungeon = true
>> exit event processing
if timehour = 5
>> tintscreen
if timehour = 9
>> tintscreen
if timehour = 18
>> tintscreen
if timehour = 20
>> tintscreen
if timehour = 24
>> timehour = 0

place the commands in a parallel common event and have it always running
and inside, you turn on the switch "indungeon" to prevent tinting without stopping time
Just saw your reply, Andar. Thank you for this! I'm keeping this in my back pocket as an alternate method of setting up time.

This is great, Maliki79! It's working well, and much cleaner than my version. My only hitch is that the first time you're on the map, it tints immediately to the "Dusk" phase of the cycle, which makes sense, but I'd like it to start out at the "Day" phase.

Thoughts on how to set up the initial event so that the map starts at "Daytime" the first time you're on it? Currently the event just switches the DayCycleCounter to ON.
Never mind, figured it out (made the "Day" Cycle Phase "0" and renumbered the other three phases accordingly).

Thank you so much for your help with this! Huge relief to get this working.
This is great, Maliki79! It's working well, and much cleaner than my version. My only hitch is that the first time you're on the map, it tints immediately to the "Dusk" phase of the cycle, which makes sense, but I'd like it to start out at the "Day" phase.

Thoughts on how to set up the initial event so that the map starts at "Daytime" the first time you're on it? Currently the event just switches the DayCycleCounter to ON.
Glad it worked well for you.

Just change the tint colors as needed.

It's your code now.
Do with it what you will.
I added comments so you could better tell which phase of day it was, but you can set those up however you need to.

Edit: Just saw your second reply.

Happy to help!

Original thread: https://forums.rpgmakerweb.com/threads/un-pausing-day-night-cycle-when-re-entering-world-map-instead-of-restarting-it.178008/