Is it possible to adjust a variable using a formula?

So, I'm making a DnD kind of game where everything happens through events and choices (you never transition into battle) and I'm having trouble finding a good way to damage the enemies.

I've already worked out how to assign HPs to monsters using variables and how to add/substract from them to eventually kill the monsters, so that part is fine. The problem is that I would like to use formulas (like skill/battle formulas, if at all possible) to affect the variable representing an enemy's HPs, and I don't know how to do it.

For instance, if a character was to use "attack", I could use the attack power of the character to define the damage it would do. That would be simple. But say the same character uses "jump" instead, and I wanted the damage to be exactly 1.5 times his attack power, is there any way I could do that using a formula (though the "script" command, maybe?) that would also take into account the enemy's defense?

Basically, I would like to adjust variables using the same kind of formulas we see in battle, and I don't know if it's possible at all.
You could do something like

$gameVariables.set(ID,$gameActors.actor(id).atk*1.5)

Why do you want to do it via script call though? Is the battle happening outside of battle?
Yes, all of the battles of my game are happening "outside" of the standard battle screen and on the same maps as other events.

And it works just fine; I just don't know how to affect a variable using a formula that would take into account stuff like Attack power and enemy's defense at the same time, or even if such a thing is possible.
You need to tell us then how you determine which is the actor and the enemy, because by default there is no enemy outside of battles.

For example, my code above

Code:
$gameVariables.set(ID,$gameActors.actor(id).atk*1.5)

Should set the game variable denoted by ID equal to the attack stat times 1.5 of the actor given by id..

But if you want to also include the "enemy" defense, we need to know how you determine the enemy in your game sincr your battles happen outside of the default battle scene..
Alright, I'm a total noob at this but I'll try to explain.

The actor, first of all, is simply the main character doing the action/activating the event. There is only one character for now, so determining his ID won't be an issue.

The "enemy", as you might have guess, is only a standard event (a sprite on a square). What I did to define his parameters (right now, only HP) is create a variable ("enemy 1") with a certain value ("10", for instance) and make it so decisions taken within the event affect the variable. You click on the event and select "Attack", the variable loses a certain number and when it reaches 0 or less, a switch is activated and the enemy is shown dead. Simple.

I could easily create variables that would define other stats for the same enemy, but really, since those stats are stable, it doesn't even have to be that complicated; that is, IF formulas are possible within a variable.

Say, for instance, that I give an enemy a defense of "2" and that I wanted my battle formula to be simply : attack power (of protagonist) - defense (of adversary) = damage done. Is there any way that could be done, with or without variables? With your code, I could affect the variable "enemy 1" with the attack power of the main character, sure, but what if I wanted to subtract the enemy's defense (which is "2") from it? Is something like "subtract (characterAttackPower - 2)" at all possible with code?

I hope this is clear.
I'll make it a bit longer than necessary to make it easier to read

Just do something like this on the script call event command

Code:
var hp = $gameVariables.value(ID of enemy HP);
var damage = $gameActors.actor(id).atk - $gameVariables.value(ID of enemy stat);
$gameVariables.set(ID of enemy HP, hp-damage);

Not sure if the game actor call is the right one though xD
Wow, thanks a lot, I'll definitely try this out!

Original thread: https://forums.rpgmakerweb.com/threads/is-it-possible-to-adjust-a-variable-using-a-formula.109051/