How to get an equipped weapon's attack value?

I want to assign the attack stat of my first actors weapon to a variable which I want to later use for other functions. In VX ace, you got that as 'a.weapons[0].params[2]'. What is the javascript equivalent that I can input into the control variable function's script box?
Moved to Learning Javascript. Please use this subforum for questions about how to write a line of code to do something in RPG Maker MV. (Plugin Support is for help using specific plugins)
In the skill/item damage formula box you can use this:
Code:
(a.weapons()[0] ? a.weapons()[0].params[2] : 0)
I.e. if the user, a, has a weapon equipped, get the ATK of their first equipped weapon, else zero.

You can set a variable's value via a damage formula, if you like, e.g.
Code:
v[1] = (a.weapons()[0] ? a.weapons()[0].params[2] : 0); a.atk * 4 - b.def * 2
This sets variable 1 equal to the ATK of first equipped weapon (or zero), then returns the standard damage formula for the actual healing/damage output.

If you're set on using Control Variables > Script, you'll need some way of specifying whose weapons you want to check. Couple of examples:
  • By actor ID (example is for actor 5):
    Code:
    var w = $gameActors.actor(5).weapons()[0]; w ? w.params[2] : 0
  • By position, a.k.a. "index", in the party (example is for index 0, i.e. the party leader):
    Code:
    var w = $gameParty.members()[0].weapons()[0]; w ? w.params[2] : 0
That worked. Thanks a lot!

Original thread: https://forums.rpgmakerweb.com/threads/how-to-get-an-equipped-weapons-attack-value.114803/