MV Set variable value to enemy's id when using a skill

Hi everyone, I'm having trouble with setting a variable's value.
Relevant plugins I'm using: all Yanfly's Action Sequences, Skill Core, STB System

So I want to do something like the act commands in Undertale, like talking to or checking the enemy's stats.
For that effect what I did is: The act commands are skills, the skill calls a common event and in it theres a script call that sets variable 1 to the same ID in the database of the enemy targeted by the skill, then a conditional branch that checks the value of that variable and depending on it does different things.
The end result is showing different information depending on the type of enemy, only one common event needed per skill.

Except I can't manage to change the variable's value in the script call. I think I only need 1 or 2 commands but it's not working.

I know next to none about js btw

-----

Examples of what I've tried in the script call:

$gameVariables.setValue(1, $gameAction._targets[0].actorId());

and

var targetId = $gameAction._targets[0].enemyId();
$gameVariables.setValue(1, targetId);

-----

Any help? I'm not even sure if this is possible, I found a similar post to this one and they couldn't find a solution there.
Where did you find any of that code? There's no such thing as $gameAction, and if there were it wouldn't have a _targets[] property.

Just use a notetag from Yanfly's Skill Core:
Code:
<Pre-Damage Eval>
$gameVariables.setValue(1, target.enemyId());
</Pre-Damage Eval>
Where did you find any of that code? There's no such thing as $gameAction, and if there were it wouldn't have a _targets[] property.

Just use a notetag from Yanfly's Skill Core:
Code:
<Pre-Damage Eval>
$gameVariables.setValue(1, target.enemyId());
</Pre-Damage Eval>
Sorry for the late response, just tried that and it's still not working.

-----

What I have in the skill's note section is:

<Pre-Damage Eval>
$gameVariables.setValue(1, target.enemyId());
</Pre-Damage Eval>

<setup action>
immortal: targets, true
perform start
action common event
</setup action>

<finish action>
immortal: targets, false
eval: BattleManager.forceAction(user); BattleManager.inputtingAction().setTarget(target); BattleManager.processTurn();
</finish action>

-----

Ignoring the eval section that also doesn't work how I want it to yet, what am I doing wrong?
I'm not as familiar with Skill Core's lunatic mode like Action Sequence's.

Also about $gameAction, as I said my coding knowledge is next to none, so I've been looking around and trying to write things myself, while also looking at the help people gave me in previous posts I made.
I don't see what your action sequence has to do with it - where's the event?

The code I gave you will set variable 1 to the enemy's ID if you have the Skill Core installed, so you need to show the event if that's not working properly.

I would submit the gentle opinion that if your coding knowledge is next to none, it doesn't make sense for you to be trying to write things yourself. Guessing at code will fail. Just ask for help if you can't find the specific answer by searching.
I don't see what your action sequence has to do with it - where's the event?

The code I gave you will set variable 1 to the enemy's ID if you have the Skill Core installed, so you need to show the event if that's not working properly.

I would submit the gentle opinion that if your coding knowledge is next to none, it doesn't make sense for you to be trying to write things yourself. Guessing at code will fail. Just ask for help if you can't find the specific answer by searching.
Ok there's been some progress

I changed the order of things in the note section, now it works perfectly! Tysm

-----

<setup action>
immortal: targets, true
perform start
eval: $gameVariables.setValue(1, target.enemyId());
action common event
</setup action>

<finish action>
immortal: targets, false
eval: BattleManager.forceAction(user); BattleManager.processTurn();
</finish action>

-----

There's just one last thing: about the eval, I want the user to regain it's turn after using the skill, so that in practice the skill won't cost a turn.

With "eval: BattleManager.forceAction(user); BattleManager.processTurn();" the user regains the turn everytime after they use the skill but the common event won't play except for the first time the skill is used.
Additionally, if I use any other skills that use common events and give the user a turn, the common event will only play after the user acts for the last time.

What should I do?
With "eval: BattleManager.forceAction(user); BattleManager.processTurn();" the user regains the turn everytime after they use the skill but the common event won't play except for the first time the skill is used.
I really don't get what that code is intended to be doing - Force Action has nothing to do with resetting your turn. (I understand what you want it to do, because you described it, but I don't understand why you think that code will do it)

You would definitely need more/different code to force the turn backwards to the actor's selection again. Also, it pretty highly depends on whether you're using the default battle system or a modified one by Yanfly or anyone else.

I would just use Yanfly's Instant Cast, put <Instant> notetag in this skill, and be done with it.
I really don't get what that code is intended to be doing - Force Action has nothing to do with resetting your turn. (I understand what you want it to do, because you described it, but I don't understand why you think that code will do it)

You would definitely need more/different code to force the turn backwards to the actor's selection again. Also, it pretty highly depends on whether you're using the default battle system or a modified one by Yanfly or anyone else.

I would just use Yanfly's Instant Cast, put <Instant> notetag in this skill, and be done with it.
Oh I didn't know about that plugin, it works perfectly too now.

If I may ask, there's another skill that's giving me trouble now that I'm using this plugin, how can I make it so that the instant cast only works the first time the skill is used on that turn? (next turn the instant cast works again once)
I can't find any info on that and the plugin itself doesn't have an immediate option for that.

Tysm for the help again!
Doesn't the plugin provide a <Cancel Instant Cast> notetag? You make the skill give the user a state that has cancel instant cast on it with a duration of 1 turn.

Or you make the skill turn a switch on and give the skill an instant cast eval of that switch, with a troop event that turns the switch back off at the beginning of each turn.

There are a variety of ways to accomplish it.
The state method is working better

Is there a way to remove the state right after finishing the instant cast?
Right now the state stays there until the end of the turn (after everyone has acted).
I'm using STB btw.
Is there a way to remove the state right after finishing the instant cast?
What would be the point? If the state is to prevent you from using the instant cast again, but you remove it after using the instant cast skill, it won't prevent anything.

Right now the state stays there until the end of the turn (after everyone has acted).
Why does that matter? If you don't give the state an icon, you couldn't even tell.

I just don't see what the issue is.
What would be the point? If the state is to prevent you from using the instant cast again, but you remove it after using the instant cast skill, it won't prevent anything.


Why does that matter? If you don't give the state an icon, you couldn't even tell.

I just don't see what the issue is.
You're right, I didn't think about check if having no icon would just leave an empty space if the actor had other states too or not, turns out it doesn't.

Thank you for everything!!

Original thread: https://forums.rpgmakerweb.com/threads/set-variable-value-to-enemys-id-when-using-a-skill.159458/