MV Inserting a stored variable into a script action

I apologize if this is a silly question to ask, but I am pretty inexperienced with javascript and was hoping someone could correct me as to the proper way to perform this script call. I am wanting to use variable 14 which is being used to store the actorId position of one of my battlers. Clearly I do not know the proper syntax or formatting in order to do so. Putting in the actorId will perform the requested action, so the script works, I just have no clue whatsoever how to insert the value of variable 14 where it belongs or how to use the proper syntax. Any help for a newbie knucklehead like myself?

Basic code that works at equipping the first character in my party.

Code:
$gameParty.members()[0].changeEquipById(1, 2);

This is the code I am using to store characterIndex to a variable, which does seem to work:

Code:
var activeFighter = BattleManagerTBS.activeEntity()._battler._characterIndex;
var value = activeFighter;
$gameVariables.setValue(15, value);
This could help for the start...
Link here to see the entire list.
I am wanting to use variable 14 which is being used to store the actorId position of one of my battlers.
Putting in the actorId will perform the requested action, so the script works, I just have no clue whatsoever how to insert the value of variable 14 where it belongs or how to use the proper syntax. Any help for a newbie knucklehead like myself?

You mean like this?
Code:
$gameParty.members()[$gameVariables.value(14)].changeEquipById(1, 2);
...just keep in mind that member index starts with 0 🙂
OMG! I think it works! I need to cleanup the code a bit, but upon initial tests my character did swap weapons in the correct order, damage was applied based on the single weapon, and status ailments were only applied from the striking weapon at that! I just made a true dual wield script! Thank you so much for the help ct_bolt!

Just to see if I am following this correctly, if I wanted to also swap out the 2 for another variable, I would write it like this?

Code:
$gameParty.members()[$gameVariables.value(14)].changeEquipById(1, [$gameVariables.value(12)]);

::edit::

Oh yea baby, it totally works, exactly as intended, and even swaps the weapons back to their original position once the double strike is over. I don't even think this technique relies on any other plugins besides Yanfly's, and it should be able to be ported to any style of battle system to top it off! I might have to release this as a plugin, at the very least after I learn a bit more about proper syntax and JS!


::edit 2::

swapping out the 2 for [$gameVariables.value(12)] didn't seem to work 🙁 I swear I am trying to work with runic technology trying to rearrange these characters into the right positions. What would be the proper syntax for this?
the second [ ] needed to be removed
Than it should look like this:
$gameParty.members()[$gameVariables.value(14)].changeEquipById(1, $gameVariables.value(12));
OMG! I think it works! I need to cleanup the code a bit, but upon initial tests my character did swap weapons in the correct order, damage was applied based on the single weapon, and status ailments were only applied from the striking weapon at that! I just made a true dual wield script! Thank you so much for the help ct_bolt!

No prob. Very happy to help out ☺️ 👍

swapping out the 2 for [$gameVariables.value(12)] didn't seem to work 🙁 I swear I am trying to work with runic technology trying to rearrange these characters into the right positions. What would be the proper syntax for this?

Soo yep as @Bex mentioned above, just got to remove the square brackets for that to be proper 😉

So it should be like this:
JavaScript:
$gameParty.members()[$gameVariables.value(14)].changeEquipById(1, $gameVariables.value(12));

Explanation of why:
Square brackets in javascript are used with an array. In this case the variable $gameParty uses a method called members which returns an array (list) of the party members.
The value inside of the square brackets is the array index.

So basically what is happening is calling a function members from the variable $gameParty variable then giving the result an index to specify which party member then that member uses a method/function called changeEquipById and is given 2 parameters the equipment type value and the itemId

More helpful info for ya:
Javascript - Array Reference: Click Here to View
Javascript - Very Basic Function Statement Reference: Click Here to View
Javascript - More Basic Function Info: Click Here to View

Hope some of that makes sense... lol :popcorn:

Happy game making! ☺️

Edit:
I also should note you don't really have to store the active battler into a game variable if you don't want.. meaning your code could just be like this if you wanted:
JavaScript:
$gameParty.members()[BattleManagerTBS.activeEntity()._battler._characterIndex].changeEquipById(1, $gameVariables.value(12));
Thank you so much for all the help! I will read over through all of the provided links to get a better understanding of the system and JS in general. The last thing I need to do is update this bit of code to grab the weapon id (it is currently grabbing the array I believe of all of the weapon mods)

Code:
var weapon = DataManager.getBaseItem(a.weapons()[0]);
var value = weapon;
$gameVariables.setValue(12, value);

I can probably find this in the script call guide, perhaps? Going to go look for it now. Then take a break from the double wield shenanagins because I don't even want to start thinking about how much a pain it is going to be to perform this same function for enemies, but maybe it won't be too difficult if I am using HIME's enemy equip script. I could likely just call a state or a skill to do the same thing I am doing here, but use his custom tags to perform the swaps instead. That actually doesn't sound too hard, heck it may even be easier, especially now that I can cross reference the working code.

I am currently on class 3 of 33 total for my SRPG project. I think I have about 30-40 skills already setup and working as intended, with the AI even using skills based on specific conditions that seems to be working much better than expected. Never thought I would really get back into RPG Maker, its been over 20 years since I was messing with RM2K, and I gotta say, it feels pretty good to be back! The community has grown a lot too, much bigger than the old crew that used to rip sprites and share tips how to make custom battle systems with common events and variables. I suppose I have a little catchup to do!


::edit::

I did find this, but I think I would rather use the above type code as the a.weapons specifically refers to the attacker if I am not mistaken. If I were to use the below code however, it would be as simple as running this after the initial actorID script, and replacing actor(5) with $gameVariables.value(14) or [$gameVariables.value(14)], if I am correct.

Code:
$gameVariables.setValue(12, $gameActors.actor(5).equips()[0].baseItemId);


This is what I came up with:

Code:
var activeFighterID = BattleManagerTBS.activeEntity()._battler._ActorId;
var value = activeFighterID;
$gameVariables.setValue(15, value);

$gameVariables.setValue(12, $gameActors.actor($gameVariables.value(15)).equips()[0].baseItemId);

Am I doin' it rite?

::final edit::

GOT IT!

Code:
$gameVariables.setValue(12, $gameActors.actor($gameVariables.value(15)).equips()[0].id);
$gameVariables.setValue(13, $gameActors.actor($gameVariables.value(15)).equips()[1].id);

Thank you again, ct_bolt and everyone else!


::edited after some testing::

It turns out the script was only working incidentally, due to an improper call returning a 0 which actually was the slot index for the character I was testing, meaning that characters in slots 1 and up do not work at the moment with this script.

The theoretical solution I have found is to instead find the character's proper slot id (in relation to party order, slots 0-3), based on who is currently the active battler. As I am using a custom battle system (LeTBS), I am of the mind that traditional calls in the battle scene will not pull the correct slot if any, so I am kind of stuck. I did go through the console and running "BattleManagerTBS.activeEntity()._battler" returns a hefty amount of results, including an actorId (5 for the character in slot 0), however I do not see anything that would associate this activeBattler with their party formation slot, which appears to be what is actually needed to run the equip character script. I had thought characterIndex was what I wanted, but it shows 0 for all battlers when active, which is why the script worked only for the lead party member (and why I thought it was returning the value I was looking for). Not really sure the best way to do this, but I think if I could find the character party slot from the actorId, I could use this to correct and complete the formula, but I am finding very little to no information on how to do this. I would think there are methods to find the character slot number based on active battler would work I imagine, but just unsure if this would work with the custom battle system, which used BattleManagerTBS instead of BattleManager.

The only other solution to this that I can think of would be using a command similar to "$gameVariables.setValue(12, $gameActors.actor($gameVariables.value(15)).equips()[0].id);", however one that equips the identified character based on their actorId instead of slot placement.

Maybe by assigning a state to the active battler via the skill used that calls this script, there could be some way to figure out the ID of the character in question. I am probably going to try some novel solutions to this tomorrow. Maybe equipping via a state with HIME's equip mod would be the best way to do this, bouncing variable equations in and out with some Yanfly scripts.

Surely there is a way around this.

-------------

This was fixed by switching $gameParty.members to $gameActors.actor, which looks for the actorId instead of the party placement. Reading through the documentation more clearly would have likely helped me prevent this mistake. Thank you again everyone for the help.

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/inserting-a-stored-variable-into-a-script-action.146837/