MV Using a variable's value that has been defined in a damage formula

Hey everyone, I'm having a bit of trouble regarding a skill I want to make for my game. Here's a quick run down of what I want it to do:
  • Player uses skill Analyze on selected enemy.
  • In the damage formula, a variable X is set to be equal to the selected enemy's ID.
  • The skill sets off a common event that checks "if variable X = , then give player Skill Y"
  • Turn ends
The thing is, in my damage formula the variable seems to be working properly. It even shows up in the console. But when it's time to use it in a common event, the variable's value is set to 0, so, I can't use it.

This is the damage formula I'm using:
Code:
$gameVariables.setValue(14, b.enemyId()); console.log("Hitting enemy ID ", $gameVariables.value(14)); a.atk * 4 - b.def * 2

Spoiler: Screenshots
1755180394022.png


Do keep in mind I'm using Chrono Engine, so the Common Event is called inside the tool event, not in the skill effects tab.

1755180425702.png

1755180491493.png

1755180512989.png

Are there any work arounds to this?

Thank you in advance to anyone who can help me with this! 😂
Have you made sure that that variable hasn't been reserved by some plugin or parallel event?
Just checked, no plugins seem to be using variable 14 for anything.
Is it always 0, every time, even if you use it multiple times?
This probably means that the common event is happening before damage calculation (from what I can remember from Chrono Engine and assuming you put the common event call in the event running the skill before damage calculation. If you put it after damage calculation in the event, it should work).

Try checking variable 14 afterward in the console to see if it is 1.

Also, in the damage formula, you can just do:
JavaScript:
v[14] = b.enemyId();
Assigning variables are fine here. Be aware of trying to call a variable that isn't defined before hand when using v[#] because it will be just that, undefined.

The .setValue() returns 0 when it is undefined.

v in the damage formula is shorthand for $gameVariables._data which is a private property.
Is it always 0, every time, even if you use it multiple times?
I just checked, and yeah, the second time and third times it updated to the correct value! Why is that?

1755194066502.png


This probably means that the common event is happening before damage calculation (from what I can remember from Chrono Engine and assuming you put the common event call in the event running the skill before damage calculation. If you put it after damage calculation in the event, it should work).

Try checking variable 14 afterward in the console to see if it is 1.

Also, in the damage formula, you can just do:
JavaScript:
v[14] = b.enemyId();
Assigning variables are fine here. Be aware of trying to call a variable that isn't defined before hand when using v[#] because it will be just that, undefined.

The .setValue() returns 0 when it is undefined.

v in the damage formula is shorthand for $gameVariables._data which is a private property.

Hey! Thank you for the reply, I'm not exactly sure how to make the damage formula register before the common event, would you happen to know how I can do that? I put the call common event line after every thing in the tool event.

1755194282084.png
I just checked, and yeah, the second time and third times it updated to the correct value! Why is that?

View attachment 347379



Hey! Thank you for the reply, I'm not exactly sure how to make the damage formula register before the common event, would you happen to know how I can do that? I put the call common event line after every thing in the tool event.

View attachment 347380
As bass2yang said, and I suspected (which is why I asked) the tool effect is happening before the damage formula is evaluated. So your common event is using whatever the previous value was.
Why does it need to use a tool effect instead of just putting the common event call in the skill effects? Does Chrono Engine just straight-up not allow that?
I searched in the plugin to see if there were any commands that could force damage that I could use in the tool event before the common event, lo and behold! There is!

1755194794269.png

1755195040392.png


1755194770204.png

1755194982610.png


Now I need to figure out how to give a skill to the player and not have it be automatically equipped while the battle's ongoing. 😢

I do have YEPs Equip Battle Skills though, so it should be reasonable to figure this one out, if anyone has any tips on how to do this, I would appreciate it!

Otherwise, thank you all so much for the support, it helped to point me in the right direction 😂
Why does it need to use a tool effect instead of just putting the common event call in the skill effects? Does Chrono Engine just straight-up not allow that?
Yes, unfortunately Chrono Engine ignores the skill effects tab, you're obligated to do it in the tool effect, unless you are adding states or debuffs, then it lets you use the skill effect.
Yes, unfortunately Chrono Engine ignores the skill effects tab, you're obligated to do it in the tool effect, unless you are adding states or debuffs, then it lets you use the skill effect.
What you'll possibly have to do is call the common event in the tool and use the "last targeted enemy ID" for which enemy it's analysing.
What you'll possibly have to do is call the common event in the tool and use the "last targeted enemy ID" for which enemy it's analysing.
Oh that is working now! I'm not sure if you saw my first reply! By forcing the damage before the common event is called, it works as inteded now! 👋
Oh that is working now! I'm not sure if you saw my first reply! By forcing the damage before the common event is called, it works as inteded now! 👋
Ah, nice, so you're sorted now?
Ah, nice, so you're sorted now?
Yes! All I need to figure out is how to make the newly gained skill not be automatically equipped mid battle (I am also using Yanfly's Equip Battle Skills) 😢

Other than that, I am totally set, your insights helped to point me in the direction I needed to solve the issue 😂

Original thread: https://forums.rpgmakerweb.com/threads/using-a-variables-value-that-has-been-defined-in-a-damage-formula.179569/