MV [SOLVED]Need Help on play animation on select enemy.

I have make an event when use item on one of enemy in troop.(I already play animation of this item in item setting.)
That item have an event is flip the coin.
if it head play effect animation(60).
if it tail play effect animation(61).

Example of enemy position.
2
1 0
3
I try this code.

$gameTroop.members()[1].startAnimation(61);

but it will play animation only at enemy at position1

I need it to be when it use item on enemy2 play animation at enemy2.

I try to get enemyIndex with

v[5]=b.enemyId(); v[10]=b.index(); in formula.(v5 is usein other event.)

$gameTroop.members()[$gameVariables.value(0010)].startAnimation(61);

But it not work out.

Thank you. and sorry for my bad at english.
I try to get enemyIndex with
v[5]=b.enemyId(); v[10]=b.index(); in formula.
This won't work, you can't set variables in the damage formula using v[x] - you can only retrieve their values.

I also don't see why you would want the enemy ID for anything. But you can use the script call for setting variables: $gameVariables.setValue(10, b.index());
$gameTroop.members()[$gameVariables.value(0010)].startAnimation(61);
This also won't work - if you put leading zeros, JavaScript will treat it as an octal value. The correct syntax is $gameVariables.value(10)
This won't work, you can't set variables in the damage formula using v[x] - you can only retrieve their values.

I also don't see why you would want the enemy ID for anything. But you can use the script call for setting variables: $gameVariables.setValue(10, b.index());

This also won't work - if you put leading zeros, JavaScript will treat it as an octal value. The correct syntax is $gameVariables.value(10)
Thank you for your help again.
with your help i can go back to artist side.
New GreatSword Idle.gif
This won't work, you can't set variables in the damage formula using v[x]
v[10]=b.index() works: v is just a local pointer to $gameVariables._data, so you can get and set values.

Like you say, though, $gameVariables.setValue is a valid alternative.
v[10]=b.index() works: v is just a local pointer to $gameVariables._data, so you can get and set values.
Yes, but the OP specified that the other variable (5) would be used in other events.

I felt it was less confusing to simply say "you can't set variables using that syntax" than to try to explain "you can use that syntax but it will only affect it within your damage formula and not carry over to the other events" 😉
Yes, but the OP specified that the other variable (5) would be used in other events.

I felt it was less confusing to simply say "you can't set variables using that syntax" than to try to explain "you can use that syntax but it will only affect it within your damage formula and not carry over to the other events" 😉
The value assignment will persist after the damage formula ends, because the value is assigned to $gameVariables._data. Only the v alias is local to the eval, not the array to which it is pointing. You can easily test this yourself if you do not believe me. 👋
The value assignment will persist after the damage formula ends, because the value is assigned to $gameVariables._data. Only the v alias is local to the eval, not the array to which it is pointing. You can easily test this yourself if you do not believe me. 👋
at first i try in formula,
v[5]=b.enemyId(); v[10]=b.index();
but only v[5] can get the value, v[10] value will get only 0 in return.

But right now i use

v[5]=b.enemyId(); $gameVariables.setValue(10, b.index());
Both v[5] and v[10] can get value in return.
@SeedofDesire - I imagine that's because you fixed the actual problem, like ATT_Turan mentioned: you originally used 0010 (octal), which equals 8 because of the leading zeroes, instead of 10:
Note that decimal literals can start with a zero (0) followed by another decimal digit, but if all digits after the leading 0 are smaller than 8, the number is interpreted as an octal number.

I'll stop replying, though, since it seems like you've got it working~
@SeedofDesire - I imagine that's because you fixed the actual problem, like ATT_Turan mentioned: you originally used 0010 (octal), which equals 8 because of the leading zeroes, instead of 10:
​

I'll stop replying, though, since it seems like you've got it working~
thank you for your concern.

at first i also use
v[0005]=b.enemyId(); v[0010]=b.index();
But only v[0005] can get value.
But only v[0005] can get value.
that is because octal 5 is decimal 5, but octal 10 is decimal 8
v[0010]=10 will store the value 10 into the variable with the ID 8, NOT into ID 10
The value assignment will persist after the damage formula ends, because the value is assigned to $gameVariables._data. Only the v alias is local to the eval, not the array to which it is pointing. You can easily test this yourself if you do not believe me. 👋
So because the $gameVariable is a defined Object type, not a default integer/string/etc. data type, setting another variable equal to it actually passes a reference to the original object? Apologies if my terminology is not quite JavaScript-correct 😉

That's...interesting. Also kind of bizarre, because I swear I had a problem at one point and someone told me it was because I was trying to use v[x] to set a value, but that advice must have also been wrong.

I didn't disbelieve you, I just didn't realize you were actually saying it would persist - the other languages I've worked with used specific syntax when making a variable a reference for another object, and I didn't see anything in the evalDamageFormula that indicated it to me.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-need-help-on-play-animation-on-select-enemy.149858/