- Joined
- Jan 2, 2014
- Messages
- 1,787
- Reaction score
- 939
- First Language
- Chinese
- Primarily Uses
- N/A
In my newly published DoubleX RMMV Formulae Edit, I tried something new to myself:
While I do know @param is supposed to work with simple values only, I'm thinking of letting users to set @param as a string storing a whole function.
Right now I use the ridiculously disastrous eval(even though I've added "use strict" for the whole plugin) to retrieve the function from the string stored in @param:
What do you think about this approach as both a plugin developer and user? What would be your approach instead if you're to let users write their own functions in @param?
* @param makeEscapeRatio * @desc Sets the party escape ratio upon battle start as makeEscapeRatio, which * must return a function that takes no arguments * The function returned by makeEscapeRatio will be bound to BattleManager * upon use * @default function() { this._escapeRatio = 0.5 * $gameParty.agility() / $gameTroop.agility(); } * * @param speed * @desc Sets the action speed as speed, which must return a function that takes * the subject's agi as the argument and returns a Number * The function returned by speed will be bound to Game_Action upon use * @default function(agi) { return agi + Math.randomInt(Math.floor(5 + agi / 4)); } * * @param lukEffectRate * @desc Sets the luk effect rate multiplier applied to adding states and * debuffs to a target as lukEffectRate, which must return a function that * takes a target as the argument and returns a Number * The function returned by lukEffectRate will be bound to Game_Action * upon use * @default function(target) { return Math.max(1.0 + (this.subject().luk - target.luk) * 0.001, 0.0); } * * @param expForLevel * @desc Sets the required experience for levelling up to level as expForLevel, * which must return a function that takes the level, actor's class, * experience basis, extra, acceleration a and b as arguments and returns * a Number * The function returned by expForLevel will be bound to Game_Actor upon * use * @default function(level, c, basis, extra, acc_a, acc_ { return Math.round(basis * (Math.pow(level - 1, 0.9 + acc_a / 250)) * level * (level + 1) / (6 + Math.pow(level, 2) / 50 / acc_ + (level - 1) * extra); } * * @param distancePerFrame * @desc Sets the characters' moving distance per frame as distancePerFrame, * which must return a function that takes no arguments and returns a * Number * The function returned by expForLevel will be bound to * Game_CharacterBase upon use * @default function() { return Math.pow(2, this.realMoveSpeed()) / 256; } * * @param makeEncounterCount * @desc Sets the number of steps needed to trigger an encounter as * makeEncounterCount, which must return a function that takes the * encounter count as the argument * The function returned by makeEncounterCount will be bound to * Game_Player upon use * @default function(n) { this._encounterCount = Math.randomInt(n) + Math.randomInt(n) + 1; }
Right now I use the ridiculously disastrous eval(even though I've added "use strict" for the whole plugin) to retrieve the function from the string stored in @param:
DoubleX_RMMV.Formulae_Edit = { // Stores all this plugin's parameters that are shown in the plugin manager params: PluginManager.parameters(DoubleX_RMMV.Formulae_Edit_File),}; // DoubleX_RMMV.Formulae_EditObject.keys(DoubleX_RMMV.Formulae_Edit.params).forEach(function(param) { DoubleX_RMMV.Formulae_Edit[param] = eval(DoubleX_RMMV.Formulae_Edit.params[param]);});
Last edited by a moderator:
