How to check if an event is in a region?

I'm trying to make a game where I want to check if an event (a stone) is in a region.

I have lots of stones and lots of regions xD So I'd like to use a script.
I'm using the conditional branch -> script and I have entered

$gameMap.event("MYEVENT").regionId() === 15

But when running it I get:

1617134073578.png


What am I doing wrong? 🙁
Try _regionId()

I'm not at my computer now but the underscore usually works for other things.
Ok I tried with $gameMap.event(017).regionId() === 15

1617134638414.png


And now .. nothing happens. Event when the event is in the region? 🙁
Try _regionId()

I'm not at my computer now but the underscore usually works for other things.

1617134723620.png


both event(017)_regionId() and event(017)._regionId() give an error.
If you can, post a screenshot of the whole event page
Write it as 17, no leading zero:
JavaScript:
$gameMap.event(17).regionId() === 15
In JavaScript, integers with leading zeroes are interpreted as octal (base 8) rather than decimal (base 10). E.g. 017 === 15 is true.
why using javascript at all?
you can do the same with a series of control variable to get the position of the event and then get location info.
Write it as 17, no leading zero:
JavaScript:
$gameMap.event(17).regionId() === 15
In JavaScript, integers with leading zeroes are interpreted as octal (base 8) rather than decimal (base 10). E.g. 017 === 15 is true.
That was it! Thank you so much!!!



why using javascript at all?
you can do the same with a series of control variable to get the position of the event and then get location info.
And create an X and Y variable for every rock? No thanks. The way with regionId works much faster 🙂
And create an X and Y variable for every rock? No thanks. The way with regionId works much faster 🙂
You can use the same 3 variables (X, Y, and region) for all rocks, no? 😅

Note that by default events are all processed in series, in a single thread. Parallel events simply run in their own interpreter rather than the main one; all Parallel interpreters are updated after the main one each frame.

So long as you put your Control Variables commands immediately before the Get Location Info and Conditional Branch, the commands should all run in one frame, meaning you can check however many rocks you like each frame with no conflicts.
Spoiler: Basic example
Code:
◆Control Variables:#0001 X = Map X of rock 1
◆Control Variables:#0002 Y = Map Y of rock 1
◆Get Location Info:R, Region ID, ({X},{Y})
◆If:R = 15
  ◆Comment:The "rock 1" event is in region 15
  ◆
:End
If you're OK with the scripted solution, though, then no worries. Happy RPG Making! 😂
You can use the same 3 variables (X, Y, and region) for all rocks, no? 😅

Note that by default events are all processed in series, in a single thread. Parallel events simply run in their own interpreter rather than the main one; all Parallel interpreters are updated after the main one each frame.

So long as you put your Control Variables commands immediately before the Get Location Info and Conditional Branch, the commands should all run in one frame, meaning you can check however many rocks you like each frame with no conflicts.
Spoiler: Basic example
Code:
◆Control Variables:#0001 X = Map X of rock 1[/INDENT]
[INDENT]◆Control Variables:#0002 Y = Map Y of rock 1[/INDENT]
[INDENT]◆Get Location Info:R, Region ID, ({X},{Y})[/INDENT]
[INDENT]◆If:R = 15[/INDENT]
[INDENT]  ◆Comment:The "rock 1" event is in region 15[/INDENT]
[INDENT]  ◆[/INDENT]
[INDENT]:End
If you're OK with the scripted solution, though, then no worries. Happy RPG Making! 😂
I tried that, but it gave me some weird effects like, I said the rock wasn't in the region while it was. And when I moved it out it said the rock was in the region... That kinda stuff.

Thanks for the tip tho 🙂
I tried that, but it gave me some weird effects like,
that just means that you made a mistake with the event, not that it can't work if done correctly.
in such cases you should give us a screenshot of the event you have, together with a description of what you want it to do (correct description) and what it does instead (failure description), and then we can usually tell you where you had your mistake and how to correct it.
I thought @caethyril had solved it for you. You could also put regions around the rock and a parallel process event on each map to check if the player is in the appropriate region. Items can also be enabled/disabled by region ID, in the case of like a pickaxe or something, without any extra event running in the background.
I solved it , thanks everyone 🙂

Original thread: https://forums.rpgmakerweb.com/threads/how-to-check-if-an-event-is-in-a-region.134928/