So, basic run down is a fight where one enemy will heal someone in the enemy troop with the lowest health in percent. Figured, alright, so take HP, divide by MHP, do that for each troop member and compare the results, using conditionals for targeting. Simple enough.
Well, if you divide HP by MHP via Control Variable, it ends up throwing out the number, as it's a float. So, then after a whole slew of other steps, I end up with this script call:
$game_variables[105] = $game_troop.members[1].hp
$game_variables[106] = $game_troop.members[1].mhp
$game_variables[102] = (($game_variables[105].to_f / $game_variables[106].to_f) *
100.0)
Where variables 105/106 are temporary, just meant to store the HP and MHP values, as you can't convert them to floats directly. So, instead, I have 2 variables that will stand-in, since they CAN be converted to floats. Take the resulting number, multiply it by 100, bam, you have a percentage.
Except now I get this lovely error:
Script 'Game_Interpreter' Line 1411: NoMethodError occurred.
undefined method 'hp' for nil:NilClass
But, here's the kicker: the call will work fine twice. It's only on the *third* call that it crashes. Am I being an idiot here? I feel like there has to be an easier way to do this, as it seems a fairly "common" mechanic.
Well, if you divide HP by MHP via Control Variable, it ends up throwing out the number, as it's a float. So, then after a whole slew of other steps, I end up with this script call:
$game_variables[105] = $game_troop.members[1].hp
$game_variables[106] = $game_troop.members[1].mhp
$game_variables[102] = (($game_variables[105].to_f / $game_variables[106].to_f) *
100.0)
Where variables 105/106 are temporary, just meant to store the HP and MHP values, as you can't convert them to floats directly. So, instead, I have 2 variables that will stand-in, since they CAN be converted to floats. Take the resulting number, multiply it by 100, bam, you have a percentage.
Except now I get this lovely error:
Script 'Game_Interpreter' Line 1411: NoMethodError occurred.
undefined method 'hp' for nil:NilClass
But, here's the kicker: the call will work fine twice. It's only on the *third* call that it crashes. Am I being an idiot here? I feel like there has to be an easier way to do this, as it seems a fairly "common" mechanic.