Time System and Advancing Hours When Sleeping

Hello, I created a standard time system with some variables and common event. And I also created a small event in the bed that makes the character sleep and fast forward 8 hours in time. The problem is that depending on the time the player goes to sleep, if these 8 hours exceed midnight, they do not reset and add up, going beyond 24 hours and crashing the system. Any help on how to solve it? (PS: Ignore that Bank Income and Respawn events)
1.png
2.png
3.png
Well, they don't add up because you don't have any code anywhere that could make them add up.

They should reset, looking at your Time System event, but you have to wait 180 or however many frames until the next time it runs. It should then advance the day and reset the hours, but if it's over it won't account for that because you didn't tell it to.

There's no smooth way for you to do this, because you made your Time System event based on frames and you're trying to modify stuff in the middle of that with your sleeping. If your Sleep event turned the Time switch off and back on again, then it should immediately start recalculating your time.

Then you just need to add logic inside your Time System event so instead of just saying "if hours >= 24, add 1 day and set hours to 0", you say "if hours >= 24, add 1 day and subtract 24 hours"
otherwise, you need to add the logic if its 21hours and add +8,
it should add + 3, + 1 day, and +5 hours which is rest of it.

so rest minutes/hours should be added after the reset which isn't
placed anywhere either.

this is mostly best in the event itself for the rest minutes/hours
to add later after the hour reset or it doesn't make sense either,
unless you skipp the rest of it.
your time system is rather badly structured, and that causes a lot of problems.

I suggest making another common event as a time system, work on that with the following comments to changes and switch after you get it working.

1) no loop - a loop like that inside an already looping parallel process is useless.
2) make a variable for seconds and count that up with less waitframes - common events reset on map change, and you'll always loose up to 180 frames due to the high wait, and it also means that the checks for correcting are rather slow (like already said above)
3) do NOT indent the conditional branhces - make every check independent on each other, so that days and months can be checked even if the hours are not yet cycling. that will allow better reaction to manual time changes.

if you have problems come back with a screenshot of the new common event after trying the corrections listed above.
Well, they don't add up because you don't have any code anywhere that could make them add up.

They should reset, looking at your Time System event, but you have to wait 180 or however many frames until the next time it runs. It should then advance the day and reset the hours, but if it's over it won't account for that because you didn't tell it to.

There's no smooth way for you to do this, because you made your Time System event based on frames and you're trying to modify stuff in the middle of that with your sleeping. If your Sleep event turned the Time switch off and back on again, then it should immediately start recalculating your time.

Then you just need to add logic inside your Time System event so instead of just saying "if hours >= 24, add 1 day and set hours to 0", you say "if hours >= 24, add 1 day and subtract 24 hours"

your time system is rather badly structured, and that causes a lot of problems.

I suggest making another common event as a time system, work on that with the following comments to changes and switch after you get it working.

1) no loop - a loop like that inside an already looping parallel process is useless.
2) make a variable for seconds and count that up with less waitframes - common events reset on map change, and you'll always loose up to 180 frames due to the high wait, and it also means that the checks for correcting are rather slow (like already said above)
3) do NOT indent the conditional branhces - make every check independent on each other, so that days and months can be checked even if the hours are not yet cycling. that will allow better reaction to manual time changes.

if you have problems come back with a screenshot of the new common event after trying the corrections listed above.

OK understood. I just followed one of those tutorials on youtube and did it like this, but I'll work on those tips, thanks a lot!
otherwise, you need to add the logic if its 21hours and add +8,
it should add + 3, + 1 day, and +5 hours which is rest of it.
Your math isn't wrong, but that's several lines more complicated than just adding the 8 then subtracting 24 when the day increments.

Original thread: https://forums.rpgmakerweb.com/threads/time-system-and-advancing-hours-when-sleeping.149892/