Check who is leader

Is there a way to check if, let's say actor 2 is the leader of the party?
Well, the person you control is the leader! Otherwise nothing of my knowledge
use control variable command to load the ID of party member #1 - that is the leader, and that way you can check it with a simple conditional branch.


(the party member ID is part of the game data sequence inside the control variable command, no need for scripts)
Maybe you can tell me how to use it as a script call?


Edit: I'll try to explain my problem... I want to check if actor 2 is the party leader and if he is then the other actors gain a passive state. Everything will be written in the notebox of the actors... I hope you understand what I mean ^^'
You can only check who is the leader (party member #1) - you cannot check for the position/index of actor ID 2. That doesn't change, no matter eventing or scripting, because actor #2 might not even be in the party. And if you want to write your own plugin for testing that, then you simply have to access the party data and check which actor is in the first element of the array.


Sorry, I can't give you the js syntax, but that should help you finding it in the code.
Ok thank you very much 😀
$gameParty.leader().actorId() === 2


will return true if actor 2 is in the lead, and false if someone else is.
I tried this out but it tells me: Cannot read property 'actorId' of undefined
where and when do you use that command? can you give us a screenshot of it?
You need to check if the leader is defined before you check which id the leader is. I know Yanfly's Auto Passive States which you are probably using starts to check passive conditionals before the leader is defined.


$gameParty.leader() && $gameParty.leader().actorId() === 2


If you want another example, I answered a very similar question here:
Pretty sure it's $gameParty.leader()._actorId === 2. Note the underscore.
Pretty sure it's $gameParty.leader()._actorId === 2. Note the underscore.

actorId() is the function that returns the _actorId variable.
yep - you should use defined functions where possible and avoid accessing internal class variables from outside the class.


If someone decided to change it from _actorId to _actor_id, any of your code using _actorId would suddenly stop working, but any of your code using actorId() would still work.


If the line is 

Code:
$gameParty.leader().actorId() === 2

and the error message is "cannot read property 'actorId' of undefined", it means $gameParty.leader() is undefined, not that actorId doesn't exist.
Don't know why anyone would change that, but good to know since I've been doing it the way I suggested and no problems have come up with the results yet.
The whole point of encapsulation is so that external functions don't need to know, or access, the internal class variables.  They use methods which return the correct variables.  There could be a valid reason to change the name if the developers wanted to add more features to actors, and actorId came to mean something different.
Looking at the code, actorId() just returns _actorId, so wouldn't that then turn up the wrong information as well?
@Yin no, because that is the purpose of those API's - the external command/function is guaranted to remain the same, but the internal implementation can change between versions, if the programmer need to change access due to other parts of the program.


If the programmers need to, then can change how the ID is stored internalle, but then they will also change the function actorID() to return the correct new value, even if that suddenly returns _actorzzz_id2 or whatever was changed internally.
@DreamXCurrently, I'm using Victor's Passive States and it doesn't work with this. If using Yanfly's Party System with this plugin I get an error: Maximum call stack size exceeded. Without this plugin nothing happens.


Using Yanfly's Auto Passive States it only works with the Party System plugin turned off.


Maybe someone has a solution for this problem? Actually, I prefer Victor's plugin right now and would appreciate it if someone could tell me a line for his plugin.


Edit: The line works with Victor's plugin but have to reload the menu. There still is the problem with Yanfly's Party System...


Also maybe someone could tell me why it has to be reloaded? :/

Original thread: https://forums.rpgmakerweb.com/threads/check-who-is-leader.61226/