(Answered) Need a cap on my variable attack power.

So I have a variety of weapons that increase stats based on things you do in the game. Saves, time, escapes, etc. How would I go about setting a cap to these stats?


Here's an example:


<Custom Parameters>


atk = $gameSystem.saveCount() / 3;


</Custom Parameters>


This takes the amount of times you saved, divides it by 3, and that's your attack power. Problem is someone could just sit there spamming save and get a bazillion attack power. How would I set a cap to this?
atk = ($gameSystem.saveCount()/3).clamp(1, 999);

// OR, to maintain easy readability:

atk = $gameSystem.saveCount() / 3;
atk = atk.clamp(1, 999);


This applies a minimum limit of 1, and maximum limit of 999 onto the value.
Ruby version, use .min and .max, min limiting a higher number, and min for determining lowest allowed number.


# Ruby (RGSS) - Clamp values between 1 and 999


atk = [1, [$game_system.save_count / 3, 999].min].max


NOTE: The one you are looking for is posted above, which is the .js version.  The version I posted is for RPG Maker VX Ace and Lower, should anyone ever find a need for it...  Notice that $gameSystem and $game_system are not the same.
Thank you very much, Dark! 😀

Original thread: https://forums.rpgmakerweb.com/threads/answered-need-a-cap-on-my-variable-attack-power.60881/