Is it possible to use dmg formula which stored in variables??

I know I can use variable by v[x] code but what I want to do here is storing the whole formula(ex: 'a.atk * 2 - b.def' to variables[1]) in variables, and using it in skill's dmg formula box, so I can just use 'v[1]' as a formula, instead of typing a.atk *2 - b.def everytime.

I tried to do this but it seems game only accept variables as numbers and not actually take in it's string and use it as formula but what do I know I'm noob anyway

So is this possible in vanila MZ or do I need a plugin?
thanks you for reading btw
I do know you could use scriptcalls functions in MV,
create a function with your formula and use that.

I'm not sure about variable with the formula though.
theoretically it might be possible by using a double eval on the variable, but that has problems in itself.

can you give a more detailed description of the effect you want to achieve ingame?
What ShadowDragon said is the best way to do this. I agree with Andar, trying to eval the code string in a variable could get wonky.

So, for example, I have this:
Code:
function TurDam(atk, def) 
{ 
    return atk * Math.log10(atk) * Math.log(1 + Math.pow((atk / def), 2)) / Math.log(2);
};
in a file called Turan.js in my plugins folder. I included that plugin in my plugin manager.

Then in the damage formula for my skills I can just do TurDam(a.atk, b.def)
theoretically it might be possible by using a double eval on the variable, but that has problems in itself.

can you give a more detailed description of the effect you want to achieve ingame?

Things mentioned in main post is really all that I want to do with this.

More specifically, I want to setup some kind of preset of damage formula that easy to edit in future.
For example, let's say I want to have two large category of skill dmg: weak / strong

weak: a.atk * 2 - b.def * 1 + (various modifiers for each individual skill)
strong: a.atk * 3 - b.def * 1 + (various modifiers for each individual skill)

obviously there will be hundred of skill in the end point of development, and suddenly I realise that I have to add something, or subtract something from that "preset" area of formula, so I have to track each skill that belongs to that category and edit every one of them one by one, which is not good.

So this is what I wanna do. Just storing a.atk * 2 - b.def * 1 into variables, and use that variables in skill damage formula box, so making formula into,
weak: v[1] + (various modifiers for each individual skill)
strong: v[2] + (various modifiers for each individual skill)

By this I can just modify one variables to edit entire category of skill.

Again thanks all of you for your attempt to helping me
in that case you're better off using @ATT_Turan suggestion of a mini-plugin.
editing that plugin is a lot easier than editing the content of the variable in a way that that can be used.
So this is what I wanna do. Just storing a.atk * 2 - b.def * 1 into variables, and use that variables in skill damage formula box, so making formula into,
weak: v[1] + (various modifiers for each individual skill)
strong: v[2] + (various modifiers for each individual skill)

By this I can just modify one variables to edit entire category of skill.
That's basically what I showed you how to do. If what you're trying to do is make the damage formulae change during gameplay depending on things you do to the variables, then you can have conditionals in the code inside the plugin function. Or you can put conditionals inside your damage formula and change what you're passing into the plugin function.
Yeah, I'd go with @ATT_Turan aswell.

Making a small plugin only containing your personal damage formulas will be way easier, orderly and risk-free than any short and wonky solution.

The advantage of putting your formulas into a plugin is that you can use all javascript functions without restrictions, as long as you return a number at the end.

Not to mention being able to use multiple lines of code instead of cramming everything inside the single line damage formula.

And you have the advantage of being able to edit the formulas at any time, affecting all skills and other objects that may use the formula all at once. So you don't have to around editing every single skill when you change something.
Custom formula in a function is definitely the way to go, I've been doing it for years now. Rather than typing out the same formula every time, it's just a matter of putting this in the formula box once it's all set up:

Code:
damage(a.atk, 4, b.def)
With 4 being the skill's power modifier.
Trying not to necropost, but this is an important concept. For games that use repeating formulas or just a handful of variants, it makes the data easier to input, yes, but more importantly to read and review.

example: the following game uses 4 primary damage formulas, which work upon a custom % of ATK, with Defense, Armor, Penetration, and Spirit.

1.50 x a.atk - (b.def * (b.arm+10/a.pen+10))
1.50 x a.atk - (b.def * (b.arm+20/a.pen+20))
1.50 x a.atk - (b.def * (b.arm+40/a.pen+40))
1.50 x a.atk - (b.def * (b.spr/a.spr))

These could be simplified as:
MagnitudeVAL x (dynamic defense)
MagnitudeVAL x (standard defense)
MagnitudeVAL x (static defense)
MagnitudeVAL x (magic defense)

With that its easy to read, and one can focus on the Magnitude and assigned formula type.

===============================================
The reason I chose to use armor and penetration, is so that armor can be applied primarily by states, and penetration can negate armor deduction without actually increasing top-end damage potential. A nice side-effect of this system is that you can determine how much the damage type should be effected by armor&penetration.. use dynamic if it's highly effected, static the damage source should be minimally affected. Use magic defense if for damage types that have no real tangibly stoppable component, such as a mind attack. For perspective, most skill magnitudes in such a game would range between 1.50 and 4.00
Necro-post notice: @ZimXero

Original thread: https://forums.rpgmakerweb.com/threads/is-it-possible-to-use-dmg-formula-which-stored-in-variables.147520/