Command for identifying attacking character

Sorry if this is a stupid question or the wrong thread.


I am working on a plugin where certain sounds are played when a character is attacking; however, I need the sounds to change depending on which character is attacking. 


What I have so far that is not working:

if (BattleManager.classId = 1) {
        instrument = "Guitar";
    } else if (BattleManager.classId = 2) {
        instrument = "Keyboard";
    } else  {
        instrument = "Bass";
    }    



I am assuming BattleManager.classId is not the right command, but all I need is to identify which character is going to attack. When that character is identified, I get the string to later identify which sound effect I want to play.


Thanks for the help!
To get the currently acting battler, you can use BattleManager._subject


However this is useless if you're not doing it at the right time. Where is that code snippet from in your plugin?


What do you define attack as? Does it include using skills, even those that don't damage an enemy? Does it include using items?
I am setting it up so the attacking character has to push a sequence of buttons in order to get the attack off. Each time a player correctly hits a button, it plays a little note. Depending on which character and which key is pressed, it will play a different instrument and note. This would be used on magic skills for both damage and healing. I don't think it would be required for items. Basically, I just want the "current character" to be the one the code is identifying.


This part of the code is in the loop that identifies which keys to press (which are pre-determined in the skill notes) and the corresponding notes. I might not need it in the loop because the character won't change until the skill has ended.
So changing it to BattleManager._subject does not seem to have changed things. The if statement seems to just use whichever option comes first.


For example:

if (BattleManager._subject = 1) {
        instrument = "Guitar";
    } else if (BattleManager._subject = 2) {
        instrument = "Keyboard";
    } else  {
        instrument = "Bass";
    }    

Will play a guitar sound.


However:

if (BattleManager._subject = 2) {
        instrument = "Keyboard";
    } else if (BattleManager._subject = 1) {
        instrument = "Guitar";
    } else  {
        instrument = "Bass";
    }    

Will play a keyboard sound.


The logic doesn't change but the order does. I would think this shouldn't change anything but it does. Not really sure what the problem is unless I need to place it in a specific part of the code.
Is that a direct copy of your code? You’re assigning 1 in your first if-statement, and since 1 is truthy, the expression evaluates to true. That’s why the first instrument assignment is always executed.
You need to use === to check for equality.


BattleManager._subject can also be a Game_Enemy or Game_Actor object, so you need to check the ID of the battler.
When I use 3 equal signs:

if (BattleManager._subject === 1) {
        instrument = "Guitar";
    } else if (BattleManager._subject === 2) {
        instrument = "Keyboard";
    } else  {
        instrument = "Bass";
    } 



It always goes for the "else" case. I'm using the standard Harold and Therese which are actors 1 & 2. This script is only active during a friendly magic skill, not enemies.
As I said, _subject is a Game_Actor or Game_Enemy object, not a number. You need to check whether it is an actor or an enemy first, and then check the actorId or enemyId
So is _subject the wrong line to use? I would never want this to be used for enemies. Sorry, I'm really not a coder and have just been trying to Frankenstein other plugins I've downloaded to get what I have so far.
Nevermind, I figured out what you meant. For those who were wondering:

if (BattleManager._subject._actorId === 0001) {
        instrument = "Guitar";
    } else if (BattleManager._subject._actorId === 0002) {
        instrument = "Keyboard";
    } else  {
        instrument = "Bass";
    }      

Original thread: https://forums.rpgmakerweb.com/threads/command-for-identifying-attacking-character.58901/