Code not working @_@

So, I tried making a plugin for full HP recovery after battle in which the game designer can customize how much % recovery occurs after each fight.

There is a problem however, it's just not working.

Help?

Code:
function toNumber(str, def) {
    return isNaN(str) ? def : +(str || def);
}
 
 var params = PluginManager.parameters('Kaisyl_Battle_Recovery');
 var synrecRecover = params['Enable Auto Recovery'].toLowerCase;
 var hpRecover = toNumber(params['HP Recovery'], 100);
 var mpRecover = toNumber(params['MP Recovery'], 100);
 var tpRecover = toNumber(params['TP Recovery'], 100);
 var clearStates = params['Clear All States'].toLowerCase;

kaisylFullRecov = Game_BattlerBase.prototype.recoverAll;
Game_BattlerBase.prototype.recoverAll = function() {
    kaisylFullRecov.call(this);
    this._hp = this.mhp * (hpRecover/100);
    this._mp = this.mmp * (mpRecover/100);
    this._tp = tpRecover;
    if (clearStates) this.clearStates();
};

kaisylEndOfWar = BattleManager.endBattle;
BattleManager.endBattle = function($gameActors) {
    kaisylEndOfWar.call(this);
    if (synrecRecover = true) {
        kaisylFullRecov();
    }
};
You haven't specified what the problem is so it's difficult to provide a definitive answer.

The first thing I notice though is this line:

Code:
var clearStates = params['Clear All States'].toLowerCase;

What this is doing is declaring clearStates as the function toLowerCase, so if I was to run

Code:
clearStates("CLEARSTATES");

It would return "clearstates". You need to add brackets after toLowerCase to call the function and return the lower case string. ie.

Code:
var clearStates = params['Clear All States'].toLowerCase();

This also applies to the synrecRecover parameter as well.

I'm going to assume this is the first part of what's causing your problem as synrecRecover would never equal true as it is a function in your code, not a boolean. This change alone won't solve the issue. In your if conditional you've used

Code:
synrecRecover = true

When your comparing two values you don't use "=", "=" is for assigning values. Instead use either "==" or "===", they are different but I won't go into that. Additionally, if you make the changes I've suggested above the value of synrecRecover will be "true", it won't be true (confusing, right?). The basic idea is one is a string (ie. has quotation marks) and the other is a boolean (true/false), they are not the same. For ease, I would suggest adding quotation marks around true. ie.

Code:
synrecRecover == "true"

Next, the kaisylFullRecov() that is called is an alias of a prototype method. This doesn't work because prototypes are used to construct the objects that appear in your game, but they themselves don't ever appear in your game, so you're calling a method on nothing effectively. What you should do, is call the function that you've aliased (ie. recoverAll()) on a suitable reference to your party members. I would suggest using either "for" or "forEach" with $gameParty.battleMembers() to build a loop.

As a side note though, you've aliased the recoverAll method. This is unnecessary. When you call your alias of the original function the battler will recover its full health, you then go on to set it to the percentage that's defined in your plugins parameters. You should either create your own method (without an alias) and call it from endBattle or just add the recovery lines into the endBattle code.

Additionally, I would advise against handling hp/mp/tp recovery by doing "this._hp = ...", because it's not recovery, it's setting the value. For recovery you would be looking for "this._hp += ...". However, this is still not the optimal way of handling it, as it can go above the actors mhp/mmp/mtp. Instead use the methods such as: Game_Battler.prototype.gainHp(value), this calls a few extra methods which in turn clamp the hp value to within 0 and it's maxHp. I'd also advise that you round your numbers before adding them to hp etc. - I can't remember if the engine does this by default but I suspect it doesn't.

As a guide I would suggest something like this:

Code:
function toNumber(str, def) {
    return isNaN(str) ? def : +(str || def);
}

var params = PluginManager.parameters('Kaisyl_Battle_Recovery');
var synrecRecover = params['Enable Auto Recovery'].toLowerCase();
var hpRecover = toNumber(params['HP Recovery'], 100);
var mpRecover = toNumber(params['MP Recovery'], 100);
var tpRecover = toNumber(params['TP Recovery'], 100);
var clearStates = params['Clear All States'].toLowerCase();


kaisylEndOfWar = BattleManager.endBattle;
BattleManager.endBattle = function(result) {
    kaisylEndOfWar.call(this, result);
    if (synrecRecover == "true") {
        var members = $gameParty.battleMembers();
        for (var i = 0; i < members.length; i++) {
           var member = members[i];
           member.gainHp(Math.floor(member.mhp * hpRecover/100));
           member.gainMp(Math.floor(member.mmp * mpRecover/100));
           member.gainTp(tpRecover);
           if (clearStates == "true") {
              member.clearStates();
           }
        }
    }
};
Thanks a ton, aliasing threw me off a lot but now I understand a few more things going on with the code I can start to work on more complex stuff.

Original thread: https://forums.rpgmakerweb.com/threads/code-not-working-_.116512/