check if tile in a particular direction is walkable?

jonthefox

Veteran
Veteran
Joined
Jan 3, 2015
Messages
1,436
Reaction score
596
Primarily Uses
Hi, so I'm making an event where the player is given a choice of walking up, down, left, or right. This happens several times in a row. So for each time the player is given the choice, I want to create a conditional branch that checks if taking a step in that particular direction is possible, i.e., if the tile is walkable (and if it's not, in the "else" branch I'll just give the player a text message to make a different choice and jump back to label). In other words, if the terrain is unwalkable whether because of the tile type or there's another event on the same layer as the player, I want it to return this as an invalid choice and prevent the player from just walking into a wall or on the same tile as an enemy or evented object or whatever. Is there an easy way to do this within the event editor? Thanks so much in advance.
 

mathmaster74

just...John
Veteran
Joined
Jun 12, 2016
Messages
285
Reaction score
193
First Language
English
Primarily Uses
RMMV
@jonthefox There are ways. Some require more events and some require a little help from outside the editor. One that works in editor would require a simple event you would duplicate on every unavailable square to create a "border", set to activate on Player Touch that has priority Above Player that produces the text message. You could also get complicated with terrain tags or regions and using scripting with the terrain tags or Yanfly plugins for regions, but if the number of events you need to set up the border is available, I think that's your best (and easiest) option.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,433
Reaction score
7,712
First Language
German
Primarily Uses
RMMV
yes, it can be evented.

Use control variable (game data section) to get current player position (two variables)
calculate the target position you want to check from there
use get location info to read whatever you want from the tile in that direction (one more variable)
check the results of the info in a conditional branch

it's only tricky if you need several information values to be checked for one position

EDIT: and that is in the event that selects the move - contrary to what @mathmaster74 said it can be done without additional events if you're willing to put in that event structure I described.
 

Ebanyle

açspasl~d~dfflass
Veteran
Joined
Sep 2, 2016
Messages
338
Reaction score
200
First Language
Portuguese
Primarily Uses
RMVXA
There's a method passable?(x,y,d) in class Game_CharacterBase that apparently checks if the tile is passable by map or event, but whenever I try to check it it gives off an undefined method error.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
There's a method passable?(x,y,d) in class Game_CharacterBase that apparently checks if the tile is passable by map or event, but whenever I try to check it it gives off an undefined method error.
How are you using it? Because I constantly use that method in my script calls and it works perfectly fine. Just use
Code:
$game_player.passable?($game_player.x, $game_player.y, direction_you_want_to_check)
If the code is too long to fit in the script call box you can just split it this way:
Code:
c = $game_player
c.passable?(c.x, c.y, dir) #change dir to be your direction
The optimal solution would be to store the direction in a variable using conditional branches and then use that variable. Direction is 2, 4, 6, 8 for (respectively) DOWN, LEFT, RIGHT, UP. Since this is a built-in method I think a script call proves to be the best option here, no unnecessary code used. However, as @Andar said, there is no need to use another event to do this, just one event that checks the tile and moves the player is enough.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,476
Members
137,824
Latest member
dobratemporal
Top