Mark All Tiles Impassible in a Tileset

Discussion in 'Learning Javascript' started by professorbeej, Mar 31, 2019.

  1. professorbeej

    professorbeej Villager Member

    Messages:
    29
    Likes Received:
    10
    Location:
    Alabama
    First Language:
    English
    Primarily Uses:
    RMMV
    Hey, folks!

    I want to get into plugin development, so I figured I'd start out by trying to alleviate an issue I have that I can't find a plugin for. Personally, I hate individually marking tiles with 0, X, * because I have far more X tiles than anything else. So I want a plugin that can either mark the entire tileset X with a script or command, or (more likely) do that on import by changing the default passage from O to X.

    I have found the documentation for the flags here: https://kinoar.github.io/rmmv-doc-web/interfaces/rpg.tileset.html

    The array info is pretty straightforward: 0x0001: Impassable downward 0x0002: Impassable leftward 0x0004: Impassable rightward 0x0008: Impassable upward 0x0010

    Or so I thought.

    When looking at the Tilesets.json, I can find no indication of these flags or how they're used. I see them (I think) in various MapXXXX.json, but again, don't know how to quite get that info into a plugin script. Both because I am crazy new to RMMV scripting and because these arrays are ginormous.

    I put this in the Learning JavaScript forum instead of the Plugin Request because I'm not so much interested in the solution to the problem as I am the fundamental how and why of the scripting behind solving it. If that makes sense.

    Thanks, y'all!
     
    #1
  2. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,454
    Likes Received:
    929
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Get ready to get your hands dirty. Do you know what 0x10 is? That's hexadecimal notation for the hex number 10, which is equivalent to 16 in decimal and 0001 0000 in binary.

    If you have a Windows computer I'd recommend opening up the Calculator app and switch to Programmer mode.

    If you open up the code you'll see stuff like this:
    Code:
    Game_Map.prototype.checkPassage = function(x, y, bit) {
        var flags = this.tilesetFlags();
        var tiles = this.allTiles(x, y);
        for (var i = 0; i < tiles.length; i++) {
            var flag = flags[tiles[i]];
            if ((flag & 0x10) !== 0)  // [*] No effect on passage
                continue;
            if ((flag & bit) === 0)   // [o] Passable
                return true;
            if ((flag & bit) === bit) // [x] Impassable
                return false;
        }
        return false;
    };
    The single "&" is a bitwise AND operation to check the passability of the tile based on the flag. You could drop a breakpoint into that function and check the values in debug to get a better sense of what it is doing.

    Edit:
    Check this function too, it uses a bitwise shift operator
    Code:
    Game_Map.prototype.isPassable = function(x, y, d) {
         return this.checkPassage(x, y, (1 << (d / 2 - 1)) & 0x0f);
    };
    
     
    Last edited: Mar 31, 2019
    #2
    professorbeej likes this.
  3. gstv87

    gstv87 Veteran Veteran

    Messages:
    1,670
    Likes Received:
    687
    First Language:
    Spanish
    Primarily Uses:
    RMVXA
    #3
    Aloe Guvner and professorbeej like this.
  4. professorbeej

    professorbeej Villager Member

    Messages:
    29
    Likes Received:
    10
    Location:
    Alabama
    First Language:
    English
    Primarily Uses:
    RMMV
    You guys are fantastic. Thank you.

    As soon as I can get back to my computer, I’m gonna start getting in over my head since I’ve never worked with hex.
     
    #4

Share This Page