Check if an event tile 2 steps infront of the player is passable or not

Hi.

I have following goal:
I wanna check if an event 2 steps infront of the player is passable or not. The tile has an event with multiple pages activaterd by self-switches. If no self-switch is on, then the event has no image, below character and passable. I tested following script:

JavaScript:
// Player faces left
$gameMap.isPassable($gamePlayer.x-2, $gamePlayer.y, $gamePlayer.direction());

Problem:
It only works with map items but not with events. They are randomly registered as non-passable. Even if their current state is below character and passable. Can't see a pattern how it registers passability of events. Let's say I push a boulder towards this tile. It will block the boulder but the conditions of passability are met. The boulder just doesn't move away from the player.

Is there an event version for $gameMap.isPassable? Or how can it be solved?
Because you have an event on that tile.

Regardless of character passability, an event will never move onto a tile with another event unless it has Through ON.
But what about checking the passability for the player? It's passable for the player but still gets detected as false. Kinda reverse situation of the event on event thing.
In theory, you can check passable and if it's met, have another check to see if those tile has any event there, and if it does, make your box through On.
I don't think isPassable() is the best thing to be using. That's a very low level function that doesn't actually interact at all with characters/events. The only thing it does is check the flags on the map tile itself.

You'd be better off using one of the Game_Character methods. What the actual game engine uses to determine whether a character can move is canPass(), but that includes the checks for events to not collide with each other.

So isMapPassable() is probably a better option.

I'm not exactly sure how you're using this script, because it's referencing the $gamePlayer for some reason...if I were doing this, the script would be getting run by the boulder event to see if it can move from its own coordinates.

For that matter, if you're doing it from the boulder, checking first for passability isn't really necessary because you could simply issue a move route and it would work or fail - except for the condition above, where there's a passable event on the tile.
To add to what's already been said, you can also do most passability checks without scripting, using Control Variables -> Game Data -> Character X/Y and Get Location Info:
  • Check area/map bounds directly from coordinates.
  • Check map passability via Terrain Tag or Region ID.
  • Check event presence via Event ID.
The boulder thing was misleading. Just used it as an example cause I used it to debug the problem by testing out how the condition interacts with other events. I don't understand why the same events have different passabilites detections on different places. Only the direction of the events differ but they aren't checked nor do they have a specific way passability like map tiles can have.

Event flow should be like this:
- Player touches/buttons Event 1
- If the Tile behind Event 1 is passable (Event = no image, below characters) for the player, then Event 1 gets executed. Tile behind Event 1 is the same like x-2 of the player if face is left.
- If the Tile behind Event 1 is not passable (Event = image in a fixed direction, same character, level) for the player, then Event 1 does nothing
- Player can change the state of relevant events

This puzzle doesn't use any switches or variables. Only self-switches and all of them for each. Each relevant Event has 5 pages. One for each self-switch (non-passable) and an empty one.

I could solve it by doing this:
- Check if all self-switches of the target event are off (is there a script call to check all of them at once?)
- If there is a map obstacle then I can use $gameMap.isPassable

That's more handwork. If there is a $gameMap.isPassable equivalent for event passability for the player then I don't have care about as much.

Does this make any sense?
If it's enough to check if your event page is "same as characters" or "below characters", there's the
$gameMap.event(X)._priorityType
(0 below, 1 same as characters, or 2 above)

Also, about the above boulder pushing example, I think VisuStella core engine changes the behavior that an event move route can't take it to an "empty" (below characters) event tile?
If there is a $gameMap.isPassable equivalent for event passability for the player then I don't have care about as much.
Weren't you already given this? caethyril explained how to do it via events and I gave you the game's functions.

There shouldn't be any question of "is there" this - if you have a question about how to implement either of those things, you'll need to be more specific about what thing you can't figure out how to do 😉
$gamePlayer.canPass(x, y, d) combines the map passability and event collisions.
To add to what's already been said, you can also do most passability checks without scripting, using Control Variables -> Game Data -> Character X/Y and Get Location Info:
  • Check area/map bounds directly from coordinates.
  • Check map passability via Terrain Tag or Region ID.
  • Check event presence via Event ID.
How can I achieve my goal using this method? Do I have to create variables for each event? I also can't see where I can check the current state of an event. An event can be passable and not depending on its self-switch. If any are on then it's not passable.

$gamePlayer.canPass(x, y, d) combines the map passability and event collisions.
Also tried this out but doesn't work.

Weren't you already given this? caethyril explained how to do it via events and I gave you the game's functions.

There shouldn't be any question of "is there" this - if you have a question about how to implement either of those things, you'll need to be more specific about what thing you can't figure out how to do 😉
I try my best to explain the problem. What is still unclear?
I try my best to explain the problem. What is still unclear?
What the problem is.

You keep saying this and that doesn't work, but you're not showing screenshots of your actual code, the actual event, for us to have any idea what you might be doing incorrectly. Just saying "this didn't work" doesn't mean anything.

You were given the correct code in several posts to be able to do what you're asking, so if you need help using it you need to show what you have so far.

With respect to the eventing route, I don't see how that can do what you want. You can see if the tile is passable and you can see if there's an event on it, but you can't via event commands check that event's priority.

You're going to have to use at least some code.
If we're just throwing every solution out there here's a plugin too
I've thought about using a script as a condition cause through eventing I can't do it. At least I don't know how. I'm totally not against code. Just hoping for a script in the condition that registers what I want. Maybe there is a misunderstanding that I wanna solve this through eventing. My goal is solving it with efficient, algorithmic script approach without using specific ID if it's avoidable. By my logic it's only (or let's say most likely) achievable by making the Player the center detection. The distance between Player and effected events is always the same.

When I say it doesn't work then I mean that the engine registers a passable event as non-passable. Console shows me false. The player can still walk on it but the event doesn't activate cause of wrongly detecting the event as non-passable. The part that doesn't work are the scripts I tested for passability detection. For now it doesn't matter if other events can walk on those events. It's all about the player now and if it's passable.

Codes I tried out that gives me false instead of true:
JavaScript:
$gamePlayer.canPass($gamePlayer.x-2, $gamePlayer.y, $gamePlayer.direction())

$gameMap.isPassable($gamePlayer.x-2, $gamePlayer.y, $gamePlayer.direction())

$gamePlayer.isMapPassable($gamePlayer.x-2, $gamePlayer.y, $gamePlayer.direction())

const event = $gameMap.event(this._eventId);
event.canPass(event.x-2, event.y, event.direction())


I just use self-switch script calls and script as conditional. I attached an image of how it looks. There isn't more of it. Each page is identical and differs only with self-switch manipulation.

If it's enough to check if your event page is "same as characters" or "below characters", there's the
$gameMap.event(X)._priorityType
(0 below, 1 same as characters, or 2 above)

Also, about the above boulder pushing example, I think VisuStella core engine changes the behavior that an event move route can't take it to an "empty" (below characters) event tile?
Sorry, I didn't see this one here somehow but this script works for passability detection.

I'm really sorry if this is still not explaining enough. I'm still learning and I wanna know why things don't work. Like why is the priorityType detection correct but not passability for the Player?

If we're just throwing every solution out there here's a plugin too
I get an "TypeError: Cannot read property '0' of undefined". Maybe cause it's not compatible with MZ?
I attached an image of how it looks. There isn't more of it.
Yes, there is.

We can't see any of the page info on the top, none of the event info on the left. We can't even see all of the text of the script calls because they're cut off on the right.

There's clearly more below.

Please provide a complete screenshot of the event as requested above.

Edit: It's because of how you're manipulating the coordinates that you pass in.

It's expected that the x, y passed into canPass() are the current coordinates of the character, and it's looking at the space in front of them, based on those coordinates and the direction.

If you want to check the tile two spaces away, you'd provide the coordinates one space away.

As a tip, what you're doing with all of those self switch calls is really inefficient for you 😉

A basic JavaScript array function can handle all of that at once.
Code:
[5, 6, 8].forEach(event => {["A", "C", "D"].forEach(switch => $gameSelfSwitches.setValue([this._mapId, event, switch], false))})

[5, 6, 8].forEach(event => $gameSelfSwitches.setValue([this._mapId, event, "B"], true))
It's expected that the x, y passed into canPass() are the current coordinates of the character, and it's looking at the space in front of them, based on those coordinates and the direction.

If you want to check the tile two spaces away, you'd provide the coordinates one space away.
Doesn't adding -2 after the Player x position do the trick to check 2 tiles away from the Player who faces left? Console shows me the position it should find.

Added new screenshot. The non-visible eventing part is same like above with different self-switch order. Other pages are the same with other self-switch on. Currently those events don't use any script calls except for self-switches. The one in the screenshot is just my last test for the detection. It's just a self-switch orgy.

As a tip, what you're doing with all of those self switch calls is really inefficient for you 😉

A basic JavaScript array function can handle all of that at once.
This is already beyond my JS skills. I'm mostly using script calls you can find in the Script Call Reference Excel you can find here somewhere.
Doesn't adding -2 after the Player x position do the trick to check 2 tiles away from the Player who faces left?
No...as I explained above, that checks them moving out of that tile. That's checking the passability for the tile 3 spaces away.

Added new screenshot.
Okay, that's a complete screenshot. But I don't see any of the code that's been discussed in this thread anywhere. So I still have no idea how you've tried to use it and what might be wrong (aside from what I said in my previous post).

This is already beyond my JS skills. I'm mostly using script calls you can find in the Script Call Reference Excel you can find here somewhere.
Okay? Feel free to copy and paste what I gave you.
Okay, that's a complete screenshot. But I don't see any of the code that's been discussed in this thread anywhere. So I still have no idea how you've tried to use it and what might be wrong (aside from what I said in my previous post).
The codes we discussed here and I tried out were all entered in the first if-condition. The one in the screenshot is just for debugging. Tried out lots of things for a passability check. Checking its direction like in the screenshot implies a passable state of that event.

No...as I explained above, that checks them moving out of that tile. That's checking the passability for the tile 3 spaces away.
Wait. I think I figuered it out with your hint. I have this situation now:

Player coordinates = 8,8
Event coordinates = 6,8
Player direction = left

$gamePlayer.x = 8
$gamePlayer.y = 8

My assumption was that

$gamePlayer.canPass($gamePlayer.x-2, $gamePlayer.y, $gamePlayer.direction())

=

$gamePlayer.canPass(6, 8,left)

Now I just removed the player direction part and it works like I wanted to

Does it work like this:
$gamePlayer.x-2, $gamePlayer.y = destination coordinates I planned. From this point the player direction decides wich tile gets checked. If Player faces left then it checks the left side of the destination. Then it's actually $gamePlayer.x-3 like you said.

After rereading your post makes me realize I just translated your explanation in noob language 😅

I didn't think of removing the player direction part. Thought it was required to work at all and playing around with direction was one of the first things I tried out and trapped me in wrongness.

$gamePlayer.direction() is optional right and what I've tested didn't accidentlly glitch to make it look like it works?
The codes we discussed here and I tried out were all entered in the first if-condition. The one in the screenshot is just for debugging.
That doesn't make sense to me. You're saying you made the first conditional check a space to the player's left, but then inside of that you're checking whether the player is facing left or right.

If the player is facing right, x-2 is not in front of them.

$gamePlayer.x-2, $gamePlayer.y = destination coordinates I planned. From this point the player direction decides wich tile gets checked. If Player faces left then it checks the left side of the destination. Then it's actually $gamePlayer.x-3 like you said.
Yes, in that situation it's checking the passability for x-3.

I didn't think of removing the player direction part. Thought it was required to work at all and playing around with direction was one of the first things I tried out and trapped me in wrongness.

$gamePlayer.direction() is optional right and what I've tested didn't accidentlly glitch to make it look like it works?
No, it's not optional - I'm not sure how you got that from anything I said. I said:
it's looking at the space in front of them, based on those coordinates and the direction.
If you don't supply a direction, then it has no way to know what's in front. It's going to be checking some failsafe 0, 0 coordinates or something.
That doesn't make sense to me. You're saying you made the first conditional check a space to the player's left, but then inside of that you're checking whether the player is facing left or right.

If the player is facing right, x-2 is not in front of them.
The code from the screenshot is from other stuff I've tested before. It checked the direction of the Event whose passability I wanted to check. This event always faces right if any self-switch is on so that's why it has this conditional. Sorry for being confusing here.

No, it's not optional - I'm not sure how you got that from anything I said. I said:
Not from you. Just tested things and removing the direction made it work. That's how I got my assumption.

I think I found out the drawback of leaving out the direction:
Without direction, the "top of the wall" autotile gets registered as fully passable, even with only one direction being passable if that's the reason.

Original thread: https://forums.rpgmakerweb.com/threads/check-if-an-event-tile-2-steps-infront-of-the-player-is-passable-or-not.161328/