How to call "isMapPassable"?

Kronicide

Veteran
Veteran
Joined
Jul 7, 2020
Messages
36
Reaction score
18
First Language
Swedish
Primarily Uses
RMMV
There's something basic I don't understand about JavaScript here, I'm sure.

This function in rpg_objects.js seems to do exactly what I need.

Skärmklipp 2020-07-16 14.57.24.png

But I don't understand how to call it. Whether I call it with this. or Game_CharacterBase. I get the error that it's not a function.

Here's the code:
JavaScript:
// caught(EVENT1, EVENT2)
// -----------------------------------
// Checks if EVENT1 has caught EVENT2.
// I.e., whether EVENT1 is right next to EVENT2, facing EVENT2, and the map
// is passable from EVENT1's square to EVENT2's square.
//
Game_Interpreter.prototype.caught = function(event1_id, event2_id){
    
    // Not even close.
    if (!this.eventInRange(event1_id, event2_id, 1)){
        return false;
    }

    // EVENT1 not facing EVENT2.
    var e1_xy = Kron.AI_base.getXY(event1_id, this.eventId());
    var e2_xy = Kron.AI_base.getXY(event2_id, this.eventId());
    var e1_dir = Kron.AI_base.getDirection(event1_id, this.eventId());

    if ((e1_dir === 2 && !(e1_xy.Y < e2_xy.Y))
        ||
        (e1_dir === 4 && !(e1_xy.X > e2_xy.X))
        ||
        (e1_dir === 8 && !(e1_xy.Y > e2_xy.Y))
        ||
        (e1_dir === 6 && !(e1_xy.X < e2_xy.X))){

        return false;
    }
    
    // EVENT1 can't pass to the square of EVENT2.
    if (!this.isMapPassable(e1_xy.X, e1_xy.Y, e1_dir)){
        return false;
    }

    // All checks are a pass.
    return true;
}

And the error message:

Skärmklipp 2020-07-16 15.00.21.png

If I just change the relevant bit above to
JavaScript:
if (!Game_CharacterBase.isMapPassable(e1_xy.X, e1_xy.Y, e1_dir)){
    return false;
}
I get the same error:

Skärmklipp 2020-07-16 15.02.22.png

I guess I simply don't know where this function lives. (I understand the official library docs to also say it's in Game_CharacterBase).
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,379
Reaction score
1,557
First Language
English
Primarily Uses
RMMV
Game_CharacterBase is the class that character types inherit from: the player, followers, events etc. Therefore, you call it from an instance of one of those classes.

You could, for example, do $gamePlayer.isMapPassable to check whether the player can pass through a given tile. Or $gameMap.events[event id].isMapPassable etc.

What you need to remember is that because you're not dealing with a static class, the functions can only be called by an instance of that class.
 

Kronicide

Veteran
Veteran
Joined
Jul 7, 2020
Messages
36
Reaction score
18
First Language
Swedish
Primarily Uses
RMMV
What you need to remember is that because you're not dealing with a static class, the functions can only be called by an instance of that class.
Thanks, I appreciate it. I think what might have confused me here is that the function doesn't actually use any properties of the calling object. It just checks generic map properties. So I'm calling it from $gamePlayer, even though I'm not (necessarily) checking whether it's the player that can pass from the given square in the given direction. It seems to work fine. (But there was another problem with the function I pasted above--just so no one tries to use it.)

Thanks again!
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,379
Reaction score
1,557
First Language
English
Primarily Uses
RMMV
Yeah, it seems like they just implemented that as a shorthand way for an event/character to check map passability by calling the one from Game_Map.
 

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

Latest Threads

Latest Profile Posts

I'm sure this question's been asked before, but I can't find an answer: is there any way to run the Steam version of RPGMaker *without* being logged into Steam? It's a frustrating extra step sometimes.
Been seeing bright flashes in the sky for a while, and thought it was my eyes playing tricks on me. Nope! Lightning. Now it's raining heavily. Seeing lightning, but not hearing thunder, is weird.
Small Update for myself:
>Two Dungeon maps are done, Dungeon 3 is in progress. Dungeon 4 needs work.
>4 characters set up out of a possible 6 but those come later.
>Hub area needs work.
>Game completion..., 20-25% maybe?
Does anyone else find writing dialogue hard?
You guys want more tutorials? Well not only are we doing new video tutorials with Driftwood, we've also brought in two contributing authors for the blog to get a new tutorial every week! First one here from @Avery
https://blog.rpgmakerweb.com/tutorials/tutorial-mapping-interior/

Next week we'll get something from @hiddenone

Forum statistics

Threads
100,712
Messages
978,627
Members
132,325
Latest member
ighjku
Top