MZ How to add a variable into a javascript plugin command dropdown box?

I made a skill that will 'analyze' an enemy's weakness, but the way it works, it has a 1 turn delay before the weakness is revealed.
So it just creates a state on the enemy that will last for 1 turn, then on expiring, it will call a common event that runs the 'Reveal Enemy Weakness' plugin command from Visustella.

>I have the proper enemy target index# saved to variable 299, But the problem is, in the plugin command dropdown there is no option except to put a static number, like 2 or 3 etc for the battler (index position) to target.
How can I put a variable (which holds the battle position) in here?

2025-01-17 16_43_13-Database pic 1.png


I've tried:

enemy index $gameVariables.value(299)
and
enemy index \v[299]


-but none of them work... T-T

Maybe if I could use a scriptcall instead of a plugin command, but there's no info about that on the plugin wiki...

I realize that the ElementalWeakness plugin is paid, but this is less about that, and more about 'how to add a variable' into a javascript plugin command dropdown which many other plugins also seem to utilize.
The same thing happens with the Free Battle Core 'add state' plugin command if anyone wants to see what I mean.
This plugin will let you use variables in plugin commands. The plugin file has English instructions
1) Make Your own Plugin, something like: ( You can then add the plugin to the engine as usual, the "Enemy" Object will exist in the Game assuming that no other object will have name conflict... I would guess that there is already object called "Enemy" in the RPG Maker 😛 tho You can just rename it to like "MyEnemyValues" and "MyEnemies" xD
JavaScript:
class EnemyValues{
    constructor(){
        this.value = [];
    }

    setValue(Index, Value){
        this.value[Index] = Value;
    }
}
var Enemy = new EnemyValues();
2) You can use it in any event as: ( That's just example )
1737164989923.png

after this line the Value of Enemy at Index 0 will be equal to 350, You can ofc. pick any index and any value You want... JS will try to handle that 😛

3) You could also add something like:
JavaScript:
class EnemyValues{
    constructor(){
        this.value = [];
    }

    setValue(Index, Value){
        this.value[Index] = Value;
    }
    
    moveValue( IndexFrom, IndexTo ){
        $gameVariables.setValue(IndexTo, this.value[IndexFrom]);
    }
}
var Enemy = new EnemyValues();
The "moveValue" function will transfer whatever in the plugin value to the Game Variables, for example using it as:
1737165118073.png

This way other Events that use Game Variables will be able to reach that value,
You simply will move the Index 0 of Enemies array to the GlobalVariables index 5

ofc. I didn't tested those scripts but if You need specific script for specific use...
please explain more clearly what You need, because I simply don't understand Your question ( fully )

Ofc. I have never touched RPG Maker MZ, this code and solution is assuming that MZ works similar to MV...
enemy index $gameVariables.value(299)
and
enemy index \v[299]
The code above were provided based on that reason,
it would have similar behavior to the one You attempted to do there...
JavaScript:
Enemy.setValue( 0, 15 ); // Enemy 0 stores value 15
Enemy.setValue( 3, 33 ); // Enemy 3 ( 4 really :P ) stores value 33
Enemy.moveValue( 3, 3 ); // Moves Value of Enemy 3 to Global Variable 3
@AquaEcho
I downloaded and activated the plugin!
However, it looks like it causes a crash when the battle gets to the common event that calls the plugin command...
2025-01-17 22_56_27-ReflectionsCrash.png

I have to wonder if the crash might be caused by the plugin command always adding an extra slash to the \v[] that I put in? Hmm... I only type in one, but two show up.

2025-01-17 22_46_59-ParameterItchanges.png


@TobiChaos
Thank you for the plugin idea! It looks like it could be powerful, but sadly I'm worthless when it comes to coding. I just wanted to try forcing the 'reveal weakness' plugin command 1 turn after the triggering skill was used. Honestly I'm really shocked the plugin doesn't have a way to specify a target by variable... T-T

Thank you both, I really appreciate the help!
So far, I fear I don't have the know-how to try customizing this system...
I have to wonder if the crash might be caused by the plugin command always adding an extra slash to the \v[] that I put in? Hmm... I only type in one, but two show up.

View attachment 329232
You can try to switch to the "Text" tab of your Parameter input and enter the escape command with one \.
It will go back to two \\ if you open this dialogue again, so it's a bit unconvenient, but you can try if one \ works.
However, it looks like it causes a crash when the battle gets to the common event that calls the plugin command...
This might be due to the wrong order.
did you add the plugin at the top or at the bottom of your plugin list?

Most code can only access functions defined above it in the code...
A workaround for this is to just do IF statements up to 8 indexes and collapse them down in the event:

Code:
◇If : Variable #0299 = 1
  ◇Plugin Command whatever enemy index 1
◇If : Variable #0299 = 2
...

You might also want to click on the Text tab to see what you can put in. Maybe a template string/literal will work in that field? (backticks are used below, not single quotes):

Code:
[`enemy index ${$gameVariables.value(299)}`]

The other approach is to try this script call based on what the plugin looks like (can't say this will work though - really just guessing at this point due to the obfuscation - also don't have it readily available to see):
JavaScript:
PluginManager.callCommand($gameMap._interpreter, 'VisuMZ_1_BattleCore', 'Mech_Analyze_Weakness', {targets: [`enemy index ${$gameVariables.value(299)}`], reveal: 1});

Also, when playtesting, start a battle with the enemy already affected with that state you used, open up the console (press F8 or F12 or whatever key opens up the console for you) and try typing in slowly:
Code:
PluginManager.callCommand($gameMap._interpreter,
To see if anything that remotely looks like VisuMZ_1_BattleCore. With VS being obfuscated, I won't count on it but it is worth a shot. It might even come up as obfuscated code, or nothing at all. Continue typing the above plugin command I wrote to see if it does anything.

Edit: Check out caethyril and another fen's post below as I don't use MZ or VS - I am sure the field that another fen pointed out should at least reveal the command and arguments required for the script call for you to try out.
Based on the syntax (and that error) I guess that VisuStella's plugin is parsing the parameter to extract the target ID/index. So if the plugin itself does not already provide a way to specify a variable value, then I think you would need:
  1. A code patch for the command parser in VisuStella's plugin;
  2. A workaround using VisuStella's plugin; or
  3. An alternative plugin.
Option 1 is unlikely because VisuStella's stuff is obfuscated. Option 2 would be feasible using branches: if variable = 1, plugin command for index 1; if variable = 2, plugin command for index 2; etc.

[Edit: actually, never mind. See Another Fen's post below, I think that'll work!]
I believe @Zia_'s suggestion would be a good bet.
Takeshis plugin should work fine on parameters that are plain text strings, every other data structure is translated into text using JSON.stringify, which results in the extra backslash.

If that does not work and/or you want to try @bass2yang's last suggestion of calling the plugin command via a script, you should be able to look up the outlines of the command in the header of VisuStellas Battle Core plugin by searching for the command name.
Since it has to be readable by the Editor, this part should not be obfuscated:
Code:
 * @command ActSeq_Mechanics_AnalyzeWeakness
 * @text MECH: Analyze Weakness
 * @desc Reveal elemental weakness(es) from target(s).
 * Requires VisuMZ_3_WeaknessDisplay!
 *
 * @arg Targets:arraystr
 * @text Targets
[...]
Both the plugin command and parameters can have different names internally than the ones shown in the editor.

I have not actually tried it, but the final plugin command should look something like this:
JavaScript:
let name = "VisuMZ_1_BattleCore";
let command = "ActSeq_Mechanics_AnalyzeWeakness";
let targets = JSON.stringify( [`enemy index ${$gameVariables.value(299)}`] );
let reveal = "1";

PluginManager.callCommand(this, name, command, {
    "Targets:arraystr" : targets,
    "Reveal:eval" : reveal
});
I only skimmed the replies and some of the stuff probably works (at least the conditionals for everything), but I vaguely remembered that Arthran made a BattleCore "patch" for this (maybe it'll work a couple years later):

😅 Oh, I think I glossed over what bass2yang wrote earlier, sorry! Another Fen's post looks promising~

Also, like Another Fen said, don't manually remove extra backslashes. A single backslash indicates an escape sequence, mainly for writing special characters. E.g. "\v" is a vertical tab (which you probably don't want here):
With no encoding, e.g. a comma in an array element would be treated as an array separator instead. The presented layer (the one you're viewing/editing) is displayed in a decoded form for intuitive/WYSIWYG editing.
I have to wonder if the crash might be caused by the plugin command always adding an extra slash to the \v[] that I put in? Hmm... I only type in one, but two show up.
Does the game still crash if you put $gameVariables.value(2) instead of the \V[2] escape code?
@AquaEcho No, there was never a crash, it's just that nothing would happen. No error would show in the console either.
@Andar, I tried both above and below the Visu scripts, no success either way.
@Zia_
That's very clever, I didn't know that was even possible!!
I was able to try all sorts of combinations suggested by you and @bass2yang, though like Andar said, it seems that it just wasn't made to take variables in this way T-T

However, 2 diff suggestions did work!!!

Success#1: Workaround with Conditionals:
I can't believe it this one was so simple, thanks to Bass2yang and @caethyril 's suggestion, which is just to use the variable in a conditional branch, with the plugin command using the static number.
----So for example:
-If BattlerIndexVar = 0
Then use PluginCommand "Reveal weakness on BattlerIndex 0"

-If BattlerIndexVar = 1
Then use PluginCommand "Reveal weakness on BattlerIndex 1"
.
.
.

etc etc.
--------------
It's a little clunky because I'd have to make like 20 of those just incase I end up with 20 battlers or something in some battle in the future, but it certainly is very effective!


Success#2: Custom Plugin courtesy of @Another Fen :

JavaScript:
let name = "VisuMZ_1_BattleCore";
let command = "ActSeq_Mechanics_AnalyzeWeakness";
let targets = JSON.stringify( [`enemy index ${$gameVariables.value(299)}`] );
let reveal = "1";

PluginManager.callCommand(this, name, command, {
    "Targets:arraystr" : targets,
    "Reveal:eval" : reveal
});

Aaaaaah, your scriptcall worked perfectly!!!!
Thank you thank youuu!!


And thank you so much to all you javascript and eventing wizards out there that helped me with this really silly and niche problem!!
😢
Glad to read it worked/helped. 🙂

It's a little clunky because I'd have to make like 20 of those just incase I end up with 20 battlers or something in some battle in the future, but it certainly is very effective!
I don't know what you are currently doing to detect whether the common event needs to be called, but chances are you won't need 20 copies of the same code if you can set one variable to the correct enemy index right before you run the common event.
chances are you won't need 20 copies of the same code if you can set one variable to the correct enemy index right before you run the common event.
Oh, that was referring to option #1, where I would be using conditionals to activate the plug-in command. However, thanks to your custom scriptcall, there’s no longer a need for that way of handling things. 😤

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/how-to-add-a-variable-into-a-javascript-plugin-command-dropdown-box.174790/