Using a variable in the <Swap> tag in Yanfly's Swap Enemies?

Hello everyone,

I'm working on using Yanfly's Swap Enemies to create an area where the player can choose an enemy to fight.

How it's going to work is that the player will input a number and it will be saved to a variable, such as v[1] (I'm using a Yanfly plugin for this as well) and be taken into a battle with an enemy with the <Swap: v[1]> tag. I thought this would work, but it somehow does not- what am I doing wrong?

Thank you in advance.
Hello! I'm not sure but... I don't think you can call variables within notetags like that. I mean, \v[1] is used to display variable values within in-game messages, I don't think it works anywhere else. 🙁
Hello! I'm not sure but... I don't think you can call variables within notetags like that. I mean, \v[1] is used to display variable values within in-game messages, I don't think it works anywhere else. 🙁

Thank you- I think that's definitely the problem then.

Is there another way to call a variable that'll work within a notetag?
"Is there another way to call a variable that'll work within a notetag?"

I don't think so, notetags seem to be pretty much like comments: they aren't interpreted by the engine by default, only by plugins designed to read them in a very specific manner. Unfortunately Yanfly's plugin doesn't seem to be designed to read variables, but that'd be a good suggestion for improving it... Too bad Yanfly can't be reached by mere mortals like us, haha!

Well... maybe you can find someone to adapt Yanfly's plugin for you? Sadly I have no Javascript skills or else I'd try to help you with that. Good luck! o/
"Is there another way to call a variable that'll work within a notetag?"

I don't think so, notetags seem to be pretty much like comments: they aren't interpreted by the engine by default, only by plugins designed to read them in a very specific manner. Unfortunately Yanfly's plugin doesn't seem to be designed to read variables, but that'd be a good suggestion for improving it... Too bad Yanfly can't be reached by mere mortals like us, haha!

Well... maybe you can find someone to adapt Yanfly's plugin for you? Sadly I have no Javascript skills or else I'd try to help you with that. Good luck! o/

All right, thank you for your help- I really appreciate it. 🙂 So it reads numbers but not variables... I don't think I can modify it- my JavaScript is rudimentary.

I'm going to leave this thread open in case someone has a solution for this problem- I think it could help a lot of people.
Hello everyone,

I'm working on using Yanfly's Swap Enemies to create an area where the player can choose an enemy to fight.

How it's going to work is that the player will input a number and it will be saved to a variable, such as v[1] (I'm using a Yanfly plugin for this as well) and be taken into a battle with an enemy with the <Swap: v[1]> tag. I thought this would work, but it somehow does not- what am I doing wrong?

Thank you in advance.
I may have found a solution to your problem.
$dataEnemies[x].swapEnemies is used to store the "swaps" of "x" enemy.
$gameVariables.value(y) is used to store the variable "y".
If you want to change the "swaps" of enemy "1", to the variable "2", have a script run this:

$dataEnemies[1].swapEnemies = [$gameVariables.value(2)];

Note:
this script has to be ran before the Battle processing,
if $gameVariables.value() is undefined or 0 the game will crash.
i'm very new to javascript, and found this through trial and error within the console and script, so it may be flawed.
I may have found a solution to your problem.
$dataEnemies[x].swapEnemies is used to store the "swaps" of "x" enemy.
$gameVariables.value(y) is used to store the variable "y".
If you want to change the "swaps" of enemy "1", to the variable "2", have a script run this:

$dataEnemies[1].swapEnemies = [$gameVariables.value(2)];

Note:
this script has to be ran before the Battle processing,
if $gameVariables.value() is undefined or 0 the game will crash.
i'm very new to javascript, and found this through trial and error within the console and script, so it may be flawed.

This worked perfectly- you are a programming wizard, @ConfliKt. Thank you so much- without you, I'd have had to scrap this feature. You really saved it. I've added your name to the credits of my game. 🙂

Thank you so much!

Original thread: https://forums.rpgmakerweb.com/threads/using-a-variable-in-the-swap-tag-in-yanflys-swap-enemies.113139/