[SOLVED]Is there a way for the system to check if a variable has increased by 1?

Status
Not open for further replies.

Triangle45

Veteran
Veteran
Joined
Aug 26, 2020
Messages
86
Reaction score
24
First Language
Spanish
Primarily Uses
RMMV
Title says it all.

I want to make a conditional reset switch everytime a day passes in-game. I can't seem to do something as simple as "If Day has increased by 1 from its previous number, then..." .
Any ideas how can I achieve this?

So far, what I have done is the following: When you go to sleep, a switch 'Slept' activates ON, then that switch resets the events in the world (you can again take a shower, buy a newspaper, things you can't do twice in a single day) but what if I don't sleep and just keep playing consuming healing items, then those one-time-per-day events wont activate again, that's why I'd like a world reset switch that detects when a day has passed.
 

Hyouryuu-Na

Sapphire Sodium
Veteran
Joined
Jun 15, 2017
Messages
930
Reaction score
2,179
First Language
Not English
Primarily Uses
RMMV
Create a new variable with the value same as Day. Check if this new variable's value is less than day. When day increases by 1, the condition will return true. So that will tell you that a new day has passed. Then you can update the new variables value to be equal to day's value again. This cycle continues.
 

BK-tdm

Manga Maker
Veteran
Joined
Jun 21, 2018
Messages
189
Reaction score
367
First Language
English
Primarily Uses
RMMV
Well you can either force a perpetual day (or let time pass till night but dont switch the day) until the player sleeps as to force a "sleep to pass the day" system, this wont work if you use a clock system for obvious reasons, as time stopping at 12pm seems unnatural.

Do you use a day/night cycle? A time cycle? if any of those 2 are present then you can simply do one of these:

In case of day/night cycle just set a variable for day, start the day at variable 1, night comes, then day again, day variable increased to 2, means a day has passed, reset everything (including day variable back to 1.

If day=2, do the sleep reset procedure, reset day to 1 and go again.

If a time/clock system is present it means you probably use a variable to manage hours passing, assuming this lets call variable "time" time starts at 0 and increases by 1 for each hour, parallel process, +1 to var every x time,simple. when the time var reaches 24, its time to switch the day, apply your "sleep reset" procedure then start again.

hour var= 0+1 every x frames, when hour var= 24 -> day has passed->reset everything.
 

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
126
Reaction score
68
First Language
French
Primarily Uses
RMMV
What you could do is lock out daily events with a self-switch.

Then, in the sleep event, make a script call with this line for each self-switch you're turning off this way:
$gameSelfSwitches.setValue([mapID, eventID, 'X'], false);
What it does is that it goes into the map whose ID was given, opens the event whose ID was given as well, and turns off the self-switch given by the letter (from A to D) written instead of X. Don't remove the little 's, they're important.

Example:
In map number 10, event number 5 is a newspaper. When you pick it up, self-switch A is turned on.
In the sleep event, I'll write $gameSelfSwitches.setValue([10, 5, 'A'], false); so there's another newspaper at the same spot when the player wakes up.

Note: you can put this line multiple times in the same script call command.
 

Triangle45

Veteran
Veteran
Joined
Aug 26, 2020
Messages
86
Reaction score
24
First Language
Spanish
Primarily Uses
RMMV
Create a new variable with the value same as Day. Check if this new variable's value is less than day. When day increases by 1, the condition will return true. So that will tell you that a new day has passed. Then you can update the new variables value to be equal to day's value again. This cycle continues.
Bless you, this worked like a charm, I'm so stupid for not seeing it before. I knew the answer to my problem was related to a second variable that checked the time but I couldn't grasp how to check both together.

If a time/clock system is present it means you probably use a variable to manage hours passing, assuming this lets call variable "time" time starts at 0 and increases by 1 for each hour, parallel process, +1 to var every x time,simple. when the time var reaches 24, its time to switch the day, apply your "sleep reset" procedure then start again.

hour var= 0+1 every x frames, when hour var= 24 -> day has passed->reset everything.
Yes in the end I followed Hyouryuu-Na's advice and now everything works fine with just a simple conditional parallel event that checks whether Days>DaysCheck and if so then Set DaysCheck=Days

What you could do is lock out daily events with a self-switch.

Then, in the sleep event, make a script call with this line for each self-switch you're turning off this way:
$gameSelfSwitches.setValue([mapID, eventID, 'X'], false);
What it does is that it goes into the map whose ID was given, opens the event whose ID was given as well, and turns off the self-switch given by the letter (from A to D) written instead of X. Don't remove the little 's, they're important.

Example:
In map number 10, event number 5 is a newspaper. When you pick it up, self-switch A is turned on.
In the sleep event, I'll write $gameSelfSwitches.setValue([10, 5, 'A'], false); so there's another newspaper at the same spot when the player wakes up.

Note: you can put this line multiple times in the same script call command.
Yes, I already block the events with a self switch so they only activate once a day, I remember that took me a long time to figure out when I first started. Sadly, I can't make scripts work and I don't know how to use them no matter what I try they always do nothing so I figured I'd make what I can with the preset commands.
I think I understand the script that you wrote and I'm gonna try it :) My workaround was that when I go to sleep, I set a common event called "SleepReset" and that reactivates every switch I want. But your idea of a script turning off the SELFswitches is brilliant that's exactly what I want but it will take me some time to implement it.
Could you please teach me how do you write the script, I mean in which command or where? I've seen people writing them in "notes", in the "script" command, in the plug in lists, and idk where does it go actually? Many thanks for your help
 

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
126
Reaction score
68
First Language
French
Primarily Uses
RMMV
In the event editor, there's a command in the 3rd page of the menu that says "Script..." right above "Plugin Command...", it should be in the bottom right corner of the menu. That's where you can write any script command, such as this remote deactivation of self-switches.
You get a text editor, and that's where you can enter the line I gave you, as many times as you need to.

Later during the development of your game, if you add another daily event, implementing it into this system will be a breeze, especially if you just have to change one common event.
It's doable without using a single plugin, so you don't even have to worry about that.
 

Triangle45

Veteran
Veteran
Joined
Aug 26, 2020
Messages
86
Reaction score
24
First Language
Spanish
Primarily Uses
RMMV
In the event editor, there's a command in the 3rd page of the menu that says "Script..." right above "Plugin Command...", it should be in the bottom right corner of the menu. That's where you can write any script command, such as this remote deactivation of self-switches.
You get a text editor, and that's where you can enter the line I gave you, as many times as you need to.

Later during the development of your game, if you add another daily event, implementing it into this system will be a breeze, especially if you just have to change one common event.
It's doable without using a single plugin, so you don't even have to worry about that.
I see, I'm trying it out right now. So you can create many different scripts for a single event? Or can each event only hold 1 script?
 

Hyouryuu-Na

Sapphire Sodium
Veteran
Joined
Jun 15, 2017
Messages
930
Reaction score
2,179
First Language
Not English
Primarily Uses
RMMV
You can have several scripts for one event. But variables (normal variables like var a, var x etc. NOT game variables. Game variables can work anywhere in the game) within a script can't be used in another script. They're 12 lines long vertically but you can minify scripts to make them fit in there.
Btw take a look at this. Lots of effecient script calls here that can save you the hassle of using multiple variables and switches:
 
Last edited:

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,767
Reaction score
5,204
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

So I need to come up with quite a few action sequences.
Was stressing about this plugin earlier, but pretty happy with how its looking now! Purple makes it pop more too!! :)
A friend requested me to do a pfp for his twitch channel, so far he approved one of my sketches, so going to digital now. The style he's looking for is quite different from my usual, hopefully I can get it right... :kaoback:
I am so hyped! A new post update and im anxious to see reactions..eeeeeeee

Forum statistics

Threads
105,483
Messages
1,014,056
Members
137,127
Latest member
noicchi
Top