Variable Max

I made some variables through events, can anyone tell me how to set the max number to 100? So say I have 99 X and I add 50 x it only goes to 100X
When you change the variable, do it via a script, like this:

Code:
Control Variables [0001: Number]: Script: [$game_variables[1] + 50, 100].max
How do I subtract variables this way?

Thank you
So, if I'm reading this right, you only want the maximum of a Variable to be 100? That's easy to do: You have to set up a Common Event with a switch to activate it, while also putting it as a Parallel Process. Feel free to use this as an example. Except since this is run in the Troops Tab, it functions differently than it does through Common events (can only be run on the Map Screen).
How do I subtract variables this way?


Thank you
You will need to explain what you are trying to do.


Control Variables already allows you to subtract variables from one another. It's the Sub operator.
Just like Arin said for the max 100, you can set up the parallel event in common events tab to keep the variable 0 and above to 100.

If Var_MaxMin >100, set to 100

If Var_MaxMin>0, set to 0

That should take care of your maximum and minimum.
Why would you use a parallel processing event to check and change something that is only going to change its value when you tell it to? If you know exactly when it's going to change (ie - when you use a Control Variables command), check it and change it straight away.


It's wasteful and poor design to have something running ALL THE TIME when you could easily check it at the exact time it changes.
How do I subtract variables this way?

Thank you
Control Variables [0001: Number]: Script: [$game_variables[1] - 50, 0].maxI haven't tested this, but it should work (assuming that you want to substract variables without getting into negatives, if you want something else, please explain.

Edit: (one error already corrected)
Control Variables [0001: Number]: Script: [$game_variables[1] - 50, 0].maxI haven't tested this, but it should work (assuming that you want to substract variables without getting into negatives, if you want something else, please explain.

Edit: (one error already corrected)
Your way does not work, it even contradicts the adding of the variable.

@Shaz I want my variable rest to be added by 80 everytime my character sleeps, but not go past 100. That part works....But I also want my hunger and thirst variables to go down when I sleep, and I don't want the numbers in the negative..
Andar's method SHOULD work. It's just the same as mine, except it's setting 0 as the minimum.


If your hunger variable is 20 and you want it to go down by 50 when your character sleeps, that would put it at -30, which would then be compared to 0, and the max of those two is 0, so it would be set to 0.


In fact, MY method is the one with the error. That should be .min at the end, not .max


So, to add to variable 1 and ensure it doesn't go over 100, use this:

Code:
Control Variables [0001: ] Script: [$game_variables[1] + 50, 100].min
And to subtract from variable 1 and ensure it doesn't go below 0, use this:
Code:
Control Variables [0001: ] Script: [$game_variables[1] - 50, 0].max
Thank you everyone it works fine, if you could help me with my other problems in my other thread it would be much appreciated
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.

Original thread: https://forums.rpgmakerweb.com/threads/variable-max.19484/