Tricky problem, need help with region IDs and separate followers

Hi everyone, I need a bit of help with something...

So I have a parallel event running in the background that checks the location of the player every 6 frames to see if they're in a region with an id of 5, and if they are then stuff happens. It works fine, and uses this script snippet in the IF conditional inside the editor:
$gameMap.regionId($gamePlayer.x,$gamePlayer.y) == 5

But what I really need is to do the same thing for all the followers in the party, separately, and I can't get that to work! I don't know JavaScript, I just got the snippet above from Googling, and it's working OK if the party is treated as one big unit, but what I need is for them to be checked individually.

So ideally I want something like this:

If party leader (slot #1, regardless of actor ID) is in a certain region, then do something.
If party follower (in slot #2, regardless of actor ID) is in a certain region, then do something else.
If party follower (in slot #3, regardless of actor ID) is in a certain region, then do something entirely else.
If party follower (in slot #4, regardless of actor ID) is in a certain region, then do something totally different.

Basically I need the script to check the current position of each party member individually, so I can do stuff to them based on where they are. Because using "$gamePlayer" like in the snippet above is tagging the entire party at the same time. Like if the party leader is standing on a lava tile, but maybe someone behind him is on an ice tile, and I have no way of checking this separately, but I need to, because lava tiles and ice tiles give different debuffs. Or if I want the entire party to go invisible if any one of them walks across a 'ghost tile', not just the party leader...

Thanks for reading! Any help would be much appreciated! 🙂

Spoiler
Unrelated to the post above, can someone tell me how I can change my avatar picture here on the forum? I registered recently, and I can't seem to find that option anywhere.
You can get a reference to the first follower (i.e. character for the second party member) like this:

$gamePlayer.followers().follower(0)
For the second follower, replace 0 with 1, etc.

With that in mind, maybe try this:

var char = $gamePlayer.followers().follower(0); $gameMap.regionId(char.x, char.y) === 5
I.e. store the follower in a temporary variable char, then do the region check as usual with $gamePlayer replaced by char.

As an aside: you can use == or === to check equality, but === (strict equality) skips type coercion. E.g. "5" == 5 is true, but "5" === 5 is false. Technical details here:

(Re changing your avatar: I think that should unlock after a certain number of posts or something.)
Thank you @caethyril , it worked perfectly! 😀

I just have a few follow-up questions if you don't mind...

Question #1: Would it be possible to set transparency for individual party members separately from each other? For example, I'm currently using this: $gamePlayer.setOpacity(75);
But this affects the entire party. Is there a way to make the party leader have one opacity value, then the first follower another, the second follower another still, etc.?

Question #2: I'm curious why it's not possible to use this:
$gameMap.regionId($gamePlayer.followers().follower(0).x,$gamePlayer.followers().follower(0).y) == 5
I tried it just to see if it'd work, and it doesn't. Is it something to do with javascript syntax? It doesn't matter in the end because I used the temporary variable like you wrote above, but I'm just curious why replacing $gamePlayer.x with $gamePlayer.followers().follower(0).x doesn't work.

Question #3:
If I want to check the position of multiple partymembers inside the same parallel event, one right after the other, in subsequent IF conditionals, can I use the same temporary variable ('char'), or does it have to be char1, char2, char3...
Great!
  1. By default all followers automatically update various properties, including opacity, to match the player character. To change this you would need a plugin.

  2. That works for me, are you certain that's exactly what you tried? Like most programming languages, JavaScript is case-sensitive.

  3. Short answer: yes, if you re-declare it each time.

    Script calls are "sandboxed": variables created by var (or let or const) inside a sandbox are deleted once the script is evaluated and will not exist outside it, hence they are "temporary". This means you can use the same variable name, e.g. char, in multiple Script commands: it will be a new variable each time.

    If you define the variable without a local declarator like var, it will be defined on the global scope, meaning it will persist after the script call ends. This is not generally recommended, though, and note that doing so will not include those values in save files.

    You can store non-numeric values in game variables if necessary. 👋
Awesome, thank you so much for the info and all your help! 🙂

Original thread: https://forums.rpgmakerweb.com/threads/tricky-problem-need-help-with-region-ids-and-separate-followers.146440/