As it is, you could do this by using a variable and adding a counter each time the clock reaches hour 0, no?
Customizable Clock and Time (Day/Night cycle)
RGSS3 Scripts (RMVX Ace)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.
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.
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:
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.
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.
@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.
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? 🙂
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? 🙂
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.
Thanks a lot for the statement. 😉 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:
What do you think of my idea mentioned it the post above? 🙂
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? 🙂
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
Hello, Heirukichi!
I love this script! but when I try to load saved data from my game, I get this error.
I'm using schala battle system and I didn't fix anything for the script, why did this happen?
I love this script! but when I try to load saved data from my game, I get this error.
I'm using schala battle system and I didn't fix anything for the script, why did this happen?
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.
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.
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.
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!!
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!!
For the sake of speaking, which script was the culprit? Did you try changing the order of that script?
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^^
So I solved it by deleting the script.
Thank you for your attention^^
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?
You can either check it only when the phase starts using this
Or you can do it with a switch using this
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.
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.
Thanks a lot, @Heirukichi. Been a while but it works just fine. 🙂
I tried $game_clock.hide and $game_clock.stop and I tried to use Tint Screen to revert the screen back to default color. Nothing works.
Any help?
Got it. Just had to let the player move a single step for refresh.
Original thread: https://forums.rpgmakerweb.com/threads/customizable-clock-and-time-day-night-cycle.97562/