For that, I would basically do this:
JavaScript:
while (Hp >= HpC) {
Hp -= 1; //or Hp = Hp - 1
};
That would reduce Hp by 1 over and over again until it was at or below HpC (I'm assuming HP and Max HP, given the variable names)
If you think it's getting stuck in the loop, put this inside the loop:
That way every time it loops, it puts the current value of Hp in the console (press F8 to access it during a playtest). That way if there's a problem, you should be able to see what it's doing.
Thank you so much for help me.
But it keeps failing, the result is still above expectations. It does not subtract 1, it does not subtract anything.
JavaScript:
var mhp = $gameActors.actor(1).mhp; var hp = $gameActors.actor(1).hp;
var AN = (hp*100)/mhp;
var Car = AN + 15;
while (Car >= mhp) {
Car = Car - 1
};
$gameScreen.showPicture(21, "barraCarga", 0, 114, 92, Car, 98, 150, 0);
var V= (AN - 61.9)/0.32; var R= (AN - 42.2)/-0.309;
$gameScreen.tintPicture(21, [R,V,-170,119], 1);
$gameVariables.setValue(189, Car);
$gameVariables.setValue(188, AN);
console.log(Car)
(AN = ancho = width) (Car = carga = load)
It is a medicine. When the medicine is drunk the common event occurs. The common event generates a higher health bar, but that higher health bar should never exceed mhp. mhp = 100, Car (Carga hp) = 115 if life bar is full. It should be Car = 100.
Car = 115 also appears on the console
$ gameVariables.setValue (189, Car); = 115
I also wanted to do it with conditional derivation.
if (Car> mhp) {Car - (Car-mhp)};
it doesn't work for me either.
--------------------------------------------------
This is the only way I found it to work.
JavaScript:
//Script:
var mhp = $gameActors.actor(1).mhp; var hp = $gameActors.actor(1).hp;
$gameVariables.setValue(20,(hp*100)/mhp);
//Event command:
♦ Variable control: #20 + 15
♦ Loop:
♦ Conditional derivation: # 20> 100
♦ Variable control: # 20 - 1
end
♦ Conditional derivation: # 20 <= 100
♦ break loop
end
//script:
var mhp = $gameActors.actor(1).mhp; var hp = $gameActors.actor(1).hp;
var AN = (hp*100)/mhp;
var Car = $gameVariables.value(20);
$gameScreen.showPicture(21, "barraCarga", 0, 114, 92, Car, 98, 150, 0);
var V= (AN - 61.9)/0.32; var R= (AN - 42.2)/-0.309;
$gameScreen.tintPicture(21, [R,V,-170,119], 1);
$gameVariables.setValue(189, Car);
$gameVariables.setValue(188, AN);
console.log(Car)