I need help getting a "variable max" setup, b/c JS is not my forte (but I do know scripting / coding, to an extent). I found some code snippets, but can't figure out how to make them work with my system. Let me explain...
I have a Fatigue System setup where I'm using a custom graphic on the HUD to track how fatigued a person is. That works great. The problem is that when I use the code snippets below to try & create a max for my "fatigue" cap, it never works.
My fpCurrent is var 19, & my fpMax is var 20. The custom graphic uses the fpMax to determine where the bar should stop, while fpCurrent is the bar that moves; this is the var I'm trying to create a max for. The graphic works as expected, but it is the variable ITSELF that will not stop at the max I set; which I've confirmed by linking [v19] to a dialogue box to see what value it has.
The code snippets I found are:
I've got everything setup as follows:
1) A global event that starts with the game, which starts tracking the fpCurrent (or var 19), incl. the Check & Clamp value, via switch;
2) An event trigger (for testing) that increases [v19] by +60 (additive; to check if the max cap works; it hasn't yet);
3) An event trigger (for testing) that decreases [v19] by -30 (subtractive)
So far... the HUD bar works just fine, but I can't see to find the right combination of placement for the code snippets above to make [var 19] stop at 100.
Any help would be appreciated. TIA.
**Edit / Addendum**
I HAVE been trying to adjust the variable by default methods (in the RMMV engine) vs using the script snippets above; so maybe that's the prob? So, I'll be playing with that option while members review this post.
I have a Fatigue System setup where I'm using a custom graphic on the HUD to track how fatigued a person is. That works great. The problem is that when I use the code snippets below to try & create a max for my "fatigue" cap, it never works.
My fpCurrent is var 19, & my fpMax is var 20. The custom graphic uses the fpMax to determine where the bar should stop, while fpCurrent is the bar that moves; this is the var I'm trying to create a max for. The graphic works as expected, but it is the variable ITSELF that will not stop at the max I set; which I've confirmed by linking [v19] to a dialogue box to see what value it has.
The code snippets I found are:
Code:
// Add or Subtract from Variable ...
tmpValue = $gameVariables.value(1) - 50;
// Check and Clamp value ...
tmpValue = tmpValue.clamp(0, 100);
// Set Variable with Clamp'ed value ...
$gameVariables.setValue(1, tmpValue);
// When you are retrieving the Variable ...
var fpCurrent = $gameVariables.value(1);
I've got everything setup as follows:
1) A global event that starts with the game, which starts tracking the fpCurrent (or var 19), incl. the Check & Clamp value, via switch;
2) An event trigger (for testing) that increases [v19] by +60 (additive; to check if the max cap works; it hasn't yet);
3) An event trigger (for testing) that decreases [v19] by -30 (subtractive)
So far... the HUD bar works just fine, but I can't see to find the right combination of placement for the code snippets above to make [var 19] stop at 100.
Any help would be appreciated. TIA.
**Edit / Addendum**
I HAVE been trying to adjust the variable by default methods (in the RMMV engine) vs using the script snippets above; so maybe that's the prob? So, I'll be playing with that option while members review this post.
.