Game Dev Contest
Join in on the Game Development contest with over $300 in prizes!
Banner Creation Contest!
Help the community out by creating your own version of the banner, and potentially having that as the main banner!
Resources
Check out our resources :D
Upgrade your account
Help out the community, and keep the website running and fully up to date by donating! :D

Need Help With Passability Check

GO TO ADMIN PANEL > ADD-ONS AND INSTALL ABSTRACT SIDEBAR TO SEE FORUMS AND SIDEBAR

CynicSyndrome

Towns Guard
Joined
Dec 6, 2015
Messages
68
Points
59
RM Skill
Writer
who can help me with this? My goal is a system of checking a tile at $gameVariables.value(x) and $gameVariables.value(y) coordinates, that the player is NOT STANDING NEXT TO, and determine which directions that tile can be entered from and exited from. Seems like no matter what I do I get "Unexpected end of input."
 
Last edited:

Xilefian

Adventurer
Joined
Jan 12, 2016
Messages
306
Points
155
RM Skill
In rpg_objects.js, line 5944:
JavaScript:
// This method of Game_Map checks if a tile can be passed when walking off it in a given direction
Game_Map.prototype.isPassable = function(x, y, d) {
    return this.checkPassage(x, y, (1 << (d / 2 - 1)) & 0x0f);
};

// It is used as such
$gameMap.isPassable( xx, yy, direction );

// Directions can be defined as:
Direction.DOWN_LEFT = 1;
Direction.DOWN = 2;
Direction.DOWN_RIGHT = 3;
Direction.LEFT = 4;
Direction.RIGHT = 6;
Direction.UP_LEFT = 7;
Direction.UP = 8;
Direction.UP_RIGHT = 9;
If you want to know what directions it can be entered from, then you'll need to find the tile in that direction and test if it can be walked off. There's a small catch to this; RPG Maker MV supports looping maps, so to check if a tile can be walked off onto a tile that loops to the other side of the map you'll need to use the rounding methods on line 5736 and 5740:
JavaScript:
// This method of Game_Map finds the adjacent X tile in the direction d
Game_Map.prototype.roundXWithDirection = function(x, d) {
    return this.roundX(x + (d === 6 ? 1 : d === 4 ? -1 : 0));
};

// This method of Game_Map finds the adjacent Y tile in the direction d
Game_Map.prototype.roundYWithDirection = function(y, d) {
    return this.roundY(y + (d === 2 ? 1 : d === 8 ? -1 : 0));
};

// It is used as such
var adjacentX = $gameMap.roundXWithDirection( xx, exitDirection );
var adjacentY = $gameMap.roundYWithDirection( yy, exitDirection );

// You can then check if the adjacent tiles are passable to xx/yy by flipping the direction
// Game_CharacterBase (for some reason) has a method to do this
var enterDirection = $gamePlayer.reverseDir( exitDirection );

// So you can now test the enter passability of xx/yy with;
$gameMap.isPassable( adjacentX, adjacentY, enterDirection );
"Unexpected end of input." is a standard Javascript error that means you messed up writing the code somewhere.
Likely, you're probably missing a closing brace } if you properly indent and format your code you'll be able to see where this is.
 

CynicSyndrome

Towns Guard
Joined
Dec 6, 2015
Messages
68
Points
59
RM Skill
Writer
thank you Xilefian. you are the second person to point me towards $gameMap.roundXWithDirection/$gameMap.roundYWithDirection so I am definitely looking into this. I have come a long way but much of this is still hieroglyphics to me, and I have not written any plugins yet. I am attempting to reach my goal using an event or events with short scripts and conditional scripts. I may be wrong, but its been my experience that a plugin is only necessary when trying to change what MV does by default in favor of something else. I have achieved quite a lot in my project using zero plugins and I am hoping not to have to start now.
[doublepost=1494185820,1494042238][/doublepost]I am trying to check each tile, one direction at a time. I'm no longer getting the error but the conditional returns false no matter what the coordinates. do you see anything wrong with this?


◆If:Script:$gameMap.isPassable($gameVariables.value(18), $gameVariables.value(19), 2)
◆Text:None, Window, Bottom
:Text:Tile at x=\V[18], y=\V[19] can be exited downward

:End
[doublepost=1548839657][/doublepost]SUCCESS! A combination of $gameMap.isPassable( x, y, d); AND $gamePlayer.canPass( x, y, d);

This FINALLY got me what I needed.
 
Top