Script call to set parameter to a value?

I remember Archeia posted that script call list, which include: 


$gameActors.actor(id).addParam(id, n)   <---- this is the script call to add parameter


But I wanted to know the script call to set the actor parameter to specified value


$gameActors.actor(id).setParam(id, n)   <---I tried this, and apparently it doesn't work....
One does not simply set a param for a battler in RMMV.


Technically speaking, You may want to check this:

Spoiler
Game_BattlerBase.prototype.param = function(paramId) {
var value = this.paramBase(paramId) + this.paramPlus(paramId);
value *= this.paramRate(paramId) * this.paramBuffRate(paramId);
var maxValue = this.paramMax(paramId);
var minValue = this.paramMin(paramId);
return Math.round(value.clamp(minValue, maxValue));
};

Instead, you may want to do this:


var actor = $gameActors.actor(actorId);
actor.addParam(paramId, val - actor.param(paramId))


Where actor.param(paramId) returns the current value of the parameter with id paramId, meaning that val should be equal to the specified value you want, in order to use the above setup to set the param to that specified value.
I already tried that (using default command) as:


Harold current Luck -> 20, I want to set it 77, so I run the following event:

  • Control Variables : #0001 Difference = Luck of Harold
  • Control Variables : #0001 Difference -= 77
  • Change Parameter: Harold, Luck - {Difference}

But the problem is that the game stats can never go below 1, but it still store the negative value.


Try: Change Parameter: Harold, Luck - 300: It will set it as Luck -> 1 instead, but the game store it as -280.


Then run the above event (or your script).


It will still be Luck -> 1 and the game store it as -204. (-280 -(1-77)).


And that's why I need it to be hard set (like variables) instead of using addition/subtraction. (sorry, I just like experimenting with the engine mechanics)
I already tried that (using default command) as:


Harold current Luck -> 20, I want to set it 77, so I run the following event:

  • Control Variables : #0001 Difference = Luck of Harold
  • Control Variables : #0001 Difference -= 77
  • Change Parameter: Harold, Luck - {Difference}

In this case, you may want to use + 57(77 - 20) instead of -57(20 - 77).


So, basically, you can check whether a battler's param greater than, equal to, or less than your specified value:


Greater than - Use decrease by (old value - new value)


Equal to - Does nothing


Less than - Use increase by(new value - old value)

Original thread: https://forums.rpgmakerweb.com/threads/script-call-to-set-parameter-to-a-value.65506/