Creating max value on variable

Hello I have problem that I can't solve. Is there any script call that can make a limit to variable ex. variable 1 is 99 and I add 50 to that variable and it stays 99 ?
not directly.
you need to make your own function for controlling the variable and adding to it. that function would add and then check if the result is higher than the maximum and if yes, set the variable to maximum.
@Andar Oh I see. Thanks for help !
I did not tested it, but should work fine
Code:
Number.prototype.clamp = function(min, max) {
  return Math.min(Math.max(this, min), max);
};

Original thread: https://forums.rpgmakerweb.com/threads/creating-max-value-on-variable.105752/