Attach a variable to a actor.

Tried figuring this out on my own but with not much luck. Is it possible to attach a variable to an actor?

Here's an example of what I'm trying to do.

If party.member's var = 1 then change their event sprite to "this"
else, it's sprite changes to "this"

The game has a camping system where depending on who is in your team will show up at camp. I have many actors that can join your team, so I want to change the sprite easily depending on who is in your team. Only way I found a way how is to check who is on your team, and possibly use Conditional branches to check if they're var = 1. If not then skip to next.

I'd love to find an easier way to do this. Any ideas? Thank you.
I'd love to find an easier way to do this. Any ideas?

one way is to have an external event change the sprites
an invisible event that uses control variables : game data : ID of Party Member
to change the sprite of event A to the picture of the actor in first position and so on.
this requires that each actor has a fixed sprite and that you keepü that list open during those development stages.

in most cases it is still easier to use different events per actor and use the event condition "actor in party" to vanish all events whose actors are not in the party.

But the best option depends on your maximum number of party members and the maximum number of actors (both numbers you didn't tell).
one way is to have an external event change the sprites
an invisible event that uses control variables : game data : ID of Party Member
to change the sprite of event A to the picture of the actor in first position and so on.
this requires that each actor has a fixed sprite and that you keepü that list open during those development stages.

in most cases it is still easier to use different events per actor and use the event condition "actor in party" to vanish all events whose actors are not in the party.

But the best option depends on your maximum number of party members and the maximum number of actors (both numbers you didn't tell).
The number of actors would be over 200 I think, it's why I'd like to check the 1st party members var status instead of using an actor ID as it would be difficult to make happen.

It would be a bit easier if only Conditionals had a "if party member 1 and var = 1 then do this" but conditionals only allow actor ids to be used instead.
You can add custom variables to actors and check them.
Although if you want to know the character graphic of a certain party member, there already is already a way for that:
This code should read the first party members (index 0) current character graphic and apply it to event 10 (or an empty graphic if the party slot is unused):
(this.character(...) only works in event script commands)
JavaScript:
let actor = $gameParty.members()[0];
let charset = actor ? actor.characterName() : "";
let index = actor ? actor.characterIndex() : 0;

let event = this.character(10);
event.setImage(charset, index);

If you want to save custom variables for each of your actors for some reason, you can usually just add them:
JavaScript:
let actor = $gameParty.members()[0];
actor.breadSlicingSkillDemonstrations = 14;

console.log($gameParty.members()[0].breadSlicingSkillDemonstrations);  // => 14
console.log($gameParty.members()[1].breadSlicingSkillDemonstrations);  // => undefined
console.log($gameParty.members()[2].breadSlicingSkillDemonstrations);  // => undefined
Of course you should be careful not to use generic names that might already be in use.
You can add custom variables to actors and check them.
Although if you want to know the character graphic of a certain party member, there already is already a way for that:
This code should read the first party members (index 0) current character graphic and apply it to event 10 (or an empty graphic if the party slot is unused):
(this.character(...) only works in event script commands)
JavaScript:
let actor = $gameParty.members()[0];
let charset = actor ? actor.characterName() : "";
let index = actor ? actor.characterIndex() : 0;

let event = this.character(10);
event.setImage(charset, index);

If you want to save custom variables for each of your actors for some reason, you can usually just add them:
JavaScript:
let actor = $gameParty.members()[0];
actor.breadSlicingSkillDemonstrations = 14;

console.log($gameParty.members()[0].breadSlicingSkillDemonstrations);  // => 14
console.log($gameParty.members()[1].breadSlicingSkillDemonstrations);  // => undefined
console.log($gameParty.members()[2].breadSlicingSkillDemonstrations);  // => undefined
Of course you should be careful not to use generic names that might already be in use.
That's it! I didn't know there was this easier way of doing what I needed. Thank you so much. The event changing sprite according to party member works perfectly. You're awesome.

I have a question about the var attached to character, say I wanted to check if the var attached to the party member is higher than 2 for example, do I have to check that only with script commands or can I use conditionals? If only with script, how could I do that? Thank you.
If I understand you correctly, generally you would have to access these variables (properties) through script commands, since nothing in the standard event commands uses them. Of course you can use the "script" option of "Control Variables" to store their current value in a regular game variable and then work with that.

You can use actor.customVariableName > 2 to check if the value is greater than 2.
You can look up Javascript comparison operators for details on this.

Most of the time adding properties to your actors would be done in a plugin, which would more easily allow you to set proper starting values and maybe even include the variable in existing game logic.
do I have to check that only with script commands or can I use conditionals?
Just to clarify, these are not mutually exclusive.

Conditional Branch (like many event commands) has a Script field. That's where you'd paste the code that @Another Fen typed in the last post.

Original thread: https://forums.rpgmakerweb.com/threads/attach-a-variable-to-a-actor.168124/