Customizable Clock and Time (Day/Night cycle)

KingHazeel

Veteran
Veteran
Joined
Jul 5, 2018
Messages
125
Reaction score
5
First Language
English
Primarily Uses
RMVXA
Wouldn't it be nice to have a function to branch how many days have already passed ingame? :) A small interface showing "Day: 1", "Day: 2" and so on would also be pretty useful I think.

Greetings,
Tw0Face
As it is, you could do this by using a variable and adding a counter each time the clock reaches hour 0, no?
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,343
Reaction score
564
First Language
Italian
Primarily Uses
RMVXA
As it is, you could do this by using a variable and adding a counter each time the clock reaches hour 0, no?
You can do more than just that. You could have a common event that updates your days counter whenever the current phase is less than the previous one (this increases the number of days even if you rest in an inn and forcibly change the time) and you could have a parallel process event that calls that common event every X frames (X is the number of frames per hour you set in the script).

This way you can call the common event every time the player rests and every time the time is supposed to change. However, I can see why having it done automatically within the script could be helpful. I'll keep this in mind for the new version of the script.
 

Tw0Face

Chief Executive Officer
Veteran
Joined
Nov 12, 2018
Messages
306
Reaction score
326
First Language
German
Primarily Uses
RMVXA
However, I can see why having it done automatically within the script could be helpful. I'll keep this in mind for the new version of the script.
Nice. :rock-right: Looking forward to it.

Greetings,
Tw0Face
 

KingHazeel

Veteran
Veteran
Joined
Jul 5, 2018
Messages
125
Reaction score
5
First Language
English
Primarily Uses
RMVXA
Awhile ago, Heirukichi was kind enough to provide a small snippet of script that I could add in schedule related events to create a wait time for parallel processes to help avoid lag.

Code:
t = $game_clock.instance_variable_get(:@time) % HCK.phase_length
t = HCK.phase_length if (t == 0)
wait(t)
The idea was to wait for the phase to finish before checking the schedule again. Recently, however, I noticed there was a small error in this. We actually want to wait for the difference between the total phase time and the time elapsed into it. So the correct script for this would be:

Code:
t = HCK.phase_length - ($game_clock.instance_variable_get(:@time) % HCK.phase_length)
wait(t)
Just thought I'd post this in case anyone else was working on NPC schedules.

EDIT: Removed the t = HCK.phase_length if (t == 0) line as well, because t will never be 0.
 
Last edited:

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,343
Reaction score
564
First Language
Italian
Primarily Uses
RMVXA
@KingHazeel you are completely right. Thank you for pointing out that mistake and posting the correct version here. I hope this helps other people that are using my script.
 

Tw0Face

Chief Executive Officer
Veteran
Joined
Nov 12, 2018
Messages
306
Reaction score
326
First Language
German
Primarily Uses
RMVXA
Hi, bro. I had some thoughts on your script lately and I got some ideas how to add a day counter. I did some improvisation to get you a screenshot. What do you think of it? I'd simply love to see something like this in your script.



I've to come up with another question. I want to add some parts to your script but I don't know exactly how to do it. I want to reset some game variables everytime a certain time (new day) is reached. If so, I want to display a help window where I can insert some info text. I know how to do this using Common Events. But I think it's way better if I could do it using your script as it won't affect the performance as much as Parallel Process Events. Want to give me some advice how I can do this? :)
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,343
Reaction score
564
First Language
Italian
Primarily Uses
RMVXA
But I think it's way better if I could do it using your script as it won't affect the performance as much as Parallel Process Events.
I think there is a misconception here. Parallel Process is not necessarily slower than putting it in a script. Of course, it depends on what you want to do and how you do it, but the overall complexity might not change much.

If you want something to happen at a certain time, you have to check if the said thing is due to happen or not. Doing so requires a check on the current time every frame (or whenever the time changes, which is a smarter way to do it). You have to check it regardless of where you put your code. In this situation, having it in a Parallel Process event or having it in the script itself is not going to change a single thing, the code is still evaluated each time there is a possibility that it could happen (which means every time your phase changes and every time you reset the clock).

Doing that in the script means adding the check to the update and the set_time methods. But it doesn't make your game run faster, it still checks if those variables have to be reset every time.
 

Tw0Face

Chief Executive Officer
Veteran
Joined
Nov 12, 2018
Messages
306
Reaction score
326
First Language
German
Primarily Uses
RMVXA
Thanks a lot for the statement. :wink: Well, if I can't make it happen using your script, I'll probably implement the check with Events. Anyway, I want to get a deeper understanding for scripting issues, so I'll try it that way first.

Forgive me for being a real script rookie but could you tell me what exactly I have to check? I think it must look somehow like this:
Code:
if ???
$game_variables[X] = 0
$game_variables[Y] = 0
$game_variables[Z] = 0
@help_window.set_text("Text")
end
What do you think of my idea mentioned it the post above? :smile:
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,343
Reaction score
564
First Language
Italian
Primarily Uses
RMVXA
What do you think of my idea mentioned it the post above?
It is feasible, but right now I cannot add it because I am very busy. As soon as I have enough free time to work on the script itself a feature that keeps the number of days played into account is definitely going to be integrated into the script.

What you want to check can be done this way:
Code:
if $game_clock.phase == YOUR_PHASE_GOES_HERE
  # reset the variables you want to reset
  $game_message.add("Variables have been reset") # using a custom window is possible as well
end
 

OBJUAN

Warper
Member
Joined
Sep 4, 2019
Messages
3
Reaction score
0
First Language
Korean
Primarily Uses
RMVXA
Hello, Heirukichi!
I love this script! but when I try to load saved data from my game, I get this error.

Script "" line 853:NoMethodError occurred.
undefined method 'visible?' for nil:NilClass

I'm using schala battle system and I didn't fix anything for the script, why did this happen?
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
1,853
Reaction score
408
First Language
English
Primarily Uses
RMVXA
Did you add the script in and tried to load your saved game?
When you add scripts into your project you are supposed to start a new game, just to be sure there will not be any problems fro loading saved data.
Try that. If not then what script is the error from? It shows "" in your message. You should always name your scripts.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,343
Reaction score
564
First Language
Italian
Primarily Uses
RMVXA
why did this happen?
As Roninator2 said, you might have loaded a game from a save prior to my script installation. If the error is generated by my script (and it is possible considering that $game_clock is saved in your save file and then loaded when loading the game), the previous save had no such a thing.
This means that, when you load the game, there is no information regarding $game_clock in it and as such its value is nil (default value for uninitialized objects). It goes without saying that methods of Game_Clock cannot be called from a nil object, as it is not an instance of that class.
 

OBJUAN

Warper
Member
Joined
Sep 4, 2019
Messages
3
Reaction score
0
First Language
Korean
Primarily Uses
RMVXA
Thank you for the answer.
Sorry for not being able to explain the problem in more detail.
When I started a new game after applying the script it worked 'normally' but I had the above problem when saving and reloading the game data.
I thought there was a conflict with other scripts in my game, so I deleted them one by one and found the cause, and it works now!
Thank you for writing the script!!
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,343
Reaction score
564
First Language
Italian
Primarily Uses
RMVXA
For the sake of speaking, which script was the culprit? Did you try changing the order of that script?
 

OBJUAN

Warper
Member
Joined
Sep 4, 2019
Messages
3
Reaction score
0
First Language
Korean
Primarily Uses
RMVXA
The main cause of the problem was a separate item storage script.
So I solved it by deleting the script.
Thank you for your attention^^
 

Tw0Face

Chief Executive Officer
Veteran
Joined
Nov 12, 2018
Messages
306
Reaction score
326
First Language
German
Primarily Uses
RMVXA
What you want to check can be done this way:
Code:
if $game_clock.phase == YOUR_PHASE_GOES_HERE
  # reset the variables you want to reset
  $game_message.add("Variables have been reset") # using a custom window is possible as well
end
Hey, thanks a lot. I tried it this way. While it seems to work, the message keeps repeating endlessly. I guess the variables might reset endlessly as well... Is there a way to execute this only once everytime the clock reaches a certain time?
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,343
Reaction score
564
First Language
Italian
Primarily Uses
RMVXA
You can either check it only when the phase starts using this
Code:
phase_start = ($game_clock.instance_variable_get(:@time) % HCK.phase_length == 0)
phase_is_right = ($game_clock.phase == YOUR_PHASE_GOES_HERE)
if phase_is_right && phase_start
  # reset the variables you want to reset
  $game_message.add("Variables have been reset") # using a custom window is possible as well
end
Or you can do it with a switch using this
Code:
unless $game_switches[YOUR_SWITCH_ID]
  if $game_clock.phase == YOUR_PHASE_GOES_HERE
    # reset the variables you want to reset
    $game_switches[YOUR_SWITCH_ID] = true
    $game_message.add("Variables have been reset") # using a custom window is possible as well
  end
else
  $game_switches[YOUR_SWITCH_ID] = false if $game_clock.phase != YOUR_PHASE_GOES_HERE
end
The first one only resets those variables when the phase is starting, the second is a bit more versatile, but the effect is substantially the same. The only issue with the first one would be when skipping phases, but the script always sets the time to the beginning of the phase so there is no practical difference between the two solutions.
 

Tw0Face

Chief Executive Officer
Veteran
Joined
Nov 12, 2018
Messages
306
Reaction score
326
First Language
German
Primarily Uses
RMVXA
Thanks a lot, @Heirukichi. Been a while but it works just fine. :smile:
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

I bought a 2 week emergency food supply. And people are already making fun of me :( I'll be fed for a bit while they go hungry when food supplies get cut(for whatever reason).
Start of semester today. This is going to be a long one.
Can't wait for the next Sonichu
Birdhouses are usually made of wood. Birds typically live in trees. Trees are wood. Birdhouses are made of birdhouses.
He just discovered cellphones...

(I don't know why am I drawing so much these days...)

Forum statistics

Threads
93,671
Messages
914,453
Members
123,261
Latest member
IBIZA
Top