Plugin Making: Add an JavaScript formula to a parameter

Hi again! 🙂

I'm trying to add a plugin parameter where a formula can be written.
I've tried several things, but the result still gives a NaN. = /
Here's the code:

Code:
 * @param CustomExpForm
 * @text Enable Custom Exp Form?
 * @type boolean
 * @on Enable
 * @off Disable
 * @desc
 * @default false
 *
 * @param ExpFormSet
 * @text Set Your Exp Form
 * @type text
 * @desc
 * @default (level-1) * 100
 * @parent CustomExpForm

var Imported = Imported || {};
Imported.Eli_Utilities = true;

var Eli = Eli || {};
Eli.Utilities = Eli.Utilities || {};

Eli.Parameters = PluginManager.parameters('Eli_Utilities');
    Eli.Param = Eli.Param || {};

Eli.Param.Utilities = {
    Customxpform: eval(Eli.Parameters['CustomExpForm']),
    Expformset: eval(Eli.Parameters['ExpFormSet']),
};

(function() {

Game_Actor.prototype.expForLevel = function(level) {
        if (Eli.Param.Utilities.Customxpform == false) {
        var c = this.currentClass();
        var basis = c.expParams[0];
        var extra = c.expParams[1];
        var acc_a = c.expParams[2];
        var acc_b = c.expParams[3];
        return Math.round(basis*(Math.pow(level-1, 0.9+acc_a/250))*level*
                (level+1)/(6+Math.pow(level,2)/50/acc_b)+(level-1)*extra);
        } else {
            return Eli.Param.Utilities.Expformset; //(level-1) * 100;
        }
    };

})();

I would give the option if the developer wants to use the default formula of Rpg Maker Mv or want to put one of their own. If he wants, then he can write his own formula (Eli.Param.Utilities.Expformset).
I got it all right. Except when I try to put this parameter in the code instead of the formula that is commented on the right side.
Then i got the NaN result.

In the "@param" i've tried several things, like change the @type (even remove it).
Also i'v tried to do this:
Expformset: eval(String(Eli.Parameters['ExpFormSet'])),

I don't know what can i do anymore uhauhauauahau
Any help?
I'v consulted this links to seek help, but i failed to achieve success.
https://forums.rpgmakerweb.com/inde...w-plugin-manager-in-rpg-maker-mv-1-5-0.79764/
https://forums.rpgmakerweb.com/index.php?threads/rpgmakermv-how-to-eval.81780/

Thanks!
Code:
var basis = c.expParams[0]; 
var extra = c.expParams[1]; 
var acc_a = c.expParams[2]; 
var acc_b = c.expParams[3];


try
Code:
var basis = c.expParams[0] || 0; 
var extra = c.expParams[1] || 0; 
var acc_a = c.expParams[2] || 0; 
var acc_b = c.expParams[3] || 0;

that || 0 should default to 0 (number) in case the content is Null.
[Edit: nvm just re-read and my original first two points were incorrect. 😴]

Rather than create an override with a copy of the default code, consider an alias:
Code:
var _Game_Actor_expForLevel = Game_Actor_expForLevel;  // alias
Game_Actor.prototype.expForLevel = function(level) {
    if (Eli.Param.Utilities.Customxpform == false) {
        return _Game_Actor_expForLevel.call(this, level);  // callback
    } else {
        return Eli.Param.Utilities.Expformset; //(level-1) * 100;
    }
};

Edit @Eliaquim: your eval is evaluated in a context where level is not defined, thus the NaN result. Try moving the eval into the expForLevel function instead:
Code:
return eval(Eli.Param.Utilities.Expformset);
1) I was able to read your first post, although you said it was incorrect, it was a lesson for me to improve the code (rewriting parameter names for example) ^^
2) Yes! I was trying to make it work first before doing the alias, as you taught me last time (thank you, it was very enlightening!).

3) IT WORKED !!! Thank you! Thank you for teaching me, I had almost reached this conclusion of eval. I'm happy to be learning. Thank you very much for helping me.
🙏


Thank you for your time! But i think you misunderstood my problem. Maybe its my bad english xD
Yay! 😂
Thank you for your time! But i think you misunderstood my problem. Maybe its my bad english xD
No worries! Your English is good, I think I just didn't read it properly. 😅
try
Code:
var basis = c.expParams[0] || 0;
var extra = c.expParams[1] || 0;
var acc_a = c.expParams[2] || 0;
var acc_b = c.expParams[3] || 0;

that || 0 should default to 0 (number) in case the content is Null.
Thank you for your time! But i think you misunderstood my problem. Maybe its my bad english xD

@caethyril The text above was directed to the @gstv87, my bad xD

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/plugin-making-add-an-javascript-formula-to-a-parameter.107550/