Help understanding passability ($dataMap.data and $dataTileset[id].flags)

Anyone know how the data array works in $dataMap?

What I understand:
There is 6 sets of width x height integers. Each sets identifies the tile (going from right to left and top to bottom). The sets are the layers, and are in order: ground, ground over, object 1, object 2, shadows, region ID. For the object layer, the integer represent the tile in the tileset.

What I don't understand:
In the ground layer, the numbers are big (like 2816), and I have no idea what they refer to.

I found a tutorial here but it seems to be missing quite a lot of information. I'm trying to find a way to identify all the tiles used, and I get how to do it for the objects layer, but I have no idea how to get the ground tiles.
Hey there,

Couldn't remember a specific guide right now (although there definitely are some), but generally the higher numbers are reserved for the A-Tilesets:
0-1023: Tileset B-E
1536-1663: Tileset A5
2048-8191: Tilesets A1-A4

Each tile in the A1-A4 sets reserves 48 indexes for the possible autotile configurations.

In theory you can use any of these tiles for any layer, although the star priority only works for tiles in the upper layer (at least in VXAce, didn't actually test that for MV / MZ).
In the ground layer, the numbers are big (like 2816), and I have no idea what they refer to.
I pulled this knowledge out of RGSS3 tilemap, but I believe this is the same in RMMZ.
0 ~ 255 = tile B
256 ~ 512 = Tile C
etc ... you get the point.

Started from 2048, it is auto tile A, IIRC it started from the top left of the tile A.
And from 2048 up to the next 48 numbers are auto tile variants from the same tile.
Autotile ID.jpg


For example, if you get the number 2048 + 32 (2080), you will get a tile that is connected to the top and bottom. If you get the number 2096, then you will get the next tile.

This number can be assigned to any layer (ground, bush, upper 1, upper 2), which is why multiple-layer was actually been there but the editor just never allows you to do that until MZ.
Hey there,

Couldn't remember a specific guide right now (although there definitely are some), but generally the higher numbers are reserved for the A-Tilesets:
0-1023: Tileset B-E
1536-1663: Tileset A5
2048-8191: Tilesets A1-A4

Each tile in the A1-A4 sets reserves 48 indexes for the possible autotile configurations.

In theory you can use any of these tiles for any layer, although the star priority only works for tiles in the upper layer (at least in VXAce, didn't actually test that for MV / MZ).
Thanks! That helps out a lot, but I still have a couple questions. So for the A1-A4 tiles, each tile in the tilesets have 48 indexes in the $dataMap.data, is that correct? And also, is there a rule for allocating the indexes? (like which tile in the tileset correspond to which integer range in the $dataMap.data?)

EDIT: @TheoAllen Ahh that would make a lot of sense! Thanks! Now on to understanding flags from the tileset data lol (you can see that I'm doing something related to passability lol).
Now on to understanding flags from the tileset data lol
Tile flags are not hard to understand, it just hard to crack for the first-timers because they are using binary to store data which usually not quite intuitive to read. I haven't look deep into this, or at least I forgot how it is structured. But I will give you a hint.

Four-direction passability is stored in a 4 digit binary. Like, 0000. For example (this may not be the real case), the first digit represents passability to move up, the second digit is the passability flag to move down. And the rest are for left and right. If you have 1111 then you have all direction passability.

With that in mind, if the tile has a passability flag as 12, if you convert it to binary, it means 1100, which is only passable up and down.

In a real case, the tile flag stored in 8 digit binary. This means it has 255 possible configurations. The four digits are for 4-direction passability. While the rest of 4-digits are for the bush flag, floor damage, stairs flag, counter flag, or maybe star passability (that's five!), I don't know. As I said, I haven't check this deeper.

My explanation might be miss, but I don't think that could be entirely wrong.
@TheoAllen Yeah I think I got the part about it being in binary, but it's hard for me to grasp the numbers it shows me. Like I see 1536, then I put in a decimal to binary converter and it gives me 11000000000. I'm trying to make sense of that number, like what each number mean.

Also, interestingly I've read on stackoverflow that using the bitwise operator (&) in javascript is not recommended since has to convert the numbers which are floats in javascript into integer. Funny how the passability calculations all use the & operator in MV and MZ.
Also, interestingly I've read on stackoverflow that using the bitwise operator (&) in javascript is not recommended since has to convert the numbers which are floats in javascript into integer. Funny how the passability calculations all use the & operator in MV and MZ.
Because it is easier to check the passability and other flags by using AND operator. It is been around like that, possibly since a long time ago. Remember, RPG Maker is old software. And reusing the same algorithm is just easier and faster for production than experimenting with a new way to calculate it. It was never been a problem before and now.

Speaking of which. for example, I have a passability flag as 1100, top-down passable. Then I check if you can move to the left.

1100
&
0010
=
0000

It is not more than 0, so it is not passable.
If I check if you can move up.

1100
&
1000
=
1000

It is more than 0, so it is passable.
@TheoAllen I see, but how are the integer converted in binary? In the tileset data object, the flags are all integers (like 1536 that I used as an example earlier).
@TheoAllen I see, but how are the integer converted in binary? In the tileset data object, the flags are all integers (like 1536 that I used as an example earlier).
You don't. Why? because you can just use the binary operator as is.

For example
JavaScript:
console.log(12 | 2) // prints 14 = 1100 OR 0010 = 1110
console.log(12 & 2) // prints 0 = 1100 AND 0010 = 0000

So yeah, you can just use that 1536 number as is.
You can check if the second digit (in binary) in 1536 is toggled on by using AND operator
> 1536 & 2
You don't. Why? because you can just use the binary operator as is.

For example
JavaScript:
console.log(12 | 2) // prints 14 = 1100 OR 0010 = 1110
console.log(12 & 2) // prints 0 = 1100 AND 0010 = 0000

So yeah, you can just use that 1536 number as is.
You can check if the second digit (in binary) in 1536 is toggled on by using AND operator
> 1536 & 2
Ahh I get it. Do you know which digit refer to what in the game? (directional passability, ladder, damage, etc.). I'm assuming do XXXX & 1/2/4/8/16/etc. to determine if that position is ON/OFF, and with that I'd just need to know what each position refer to in the engine.

Moving this thread to Learning Javascript since this has evolved into a more in-depth thread about javascript and the base architecture of the RPG Maker engine.

The tile ids do not hold any of that information (it's not even stored in the map file, that data comes from the tileset). The integer values refer to different tiles and there's no binary involved there.

An auto tile can have up to 48 different shapes, each one is stored as a separate integer value on the map.
The tile ids do not hold any of that information (it's not even stored in the map file, that data comes from the tileset). The integer values refer to different tiles and there's no binary involved there.

An auto tile can have up to 48 different shapes, each one is stored as a separate integer value on the map.
Yeah I figured that out with Theo. Figured I'd just do ($dataMap.data[the tile] - 2048) / 48 to get the tile.

The bitwise operator part was just me trying to understand all the numbers in the flags array inside the $dataTilesets object.

EDIT: Alright, I found a post from Shaz:
Once you have the value, convert it to binary (this is just if you're trying to work out what the settings all are - if you're writing a script, no conversion is necessary because it's obviously stored in binary in memory already). The bits, reading from right to left, if set to 1 are:
- impassable down
- impassable on left
- impassable on right
- impassable up

- star tile
- ladder
- bush
- counter (for A2 set also indicates table)

- damage
- passable by boat
- passable by ship
- airship can land

- next 3 combine for terrain

and the leftmost bit is unused.

I think 🙂

I think Shaz goes on to add that the game checks for a passability or non-passability from the highest layer down to the lowest layer. Once it gets an answer, it skips the lower layers. If it gets star (the on top passability) it skips to the next layer.
Not sure if/where they are listed in the MZ manual, but as far as I remember they should not have changed since VXAce, which lists them like this:
flags
The flags table. A 1-dimensional array containing a variety of flags (Table).
Uses tile IDs as subscripts. The correspondence of each bit is as shown below:
  • 0x0001: Impassable downward
  • 0x0002: Impassable leftward
  • 0x0004: Impassable rightward
  • 0x0008: Impassable upward
  • 0x0010: Display on normal character
  • 0x0020: Ladder
  • 0x0040: Bush
  • 0x0080: Counter
  • 0x0100: Damage floor
  • 0x0200: Impassable by boat
  • 0x0400: Impassable by ship
  • 0x0800: Airship cannot land
  • 0xF000: Terrain tag
This manual does not discuss bit operations, but they are similar to those in C. We recommend an Internet search using keywords such as "hexadecimal bit operations" when necessary.

Edit: Too slow.
These are the tests that RM does on the flags:

Code:
flag & 16 !== 0 // star passability
flag & 1 === 0 // DOWN passable
flag & 2 === 0 // LEFT passable
flag & 4 === 0 // RIGHT passable
flag & 8 === 0 // UP passable
flag & 32 !== 0 // LADDER
flag & 64 !== 0 // BUSH
flag & 128 !== 0 // COUNTER
flag & 256 !== 0 // DAMAGE
flag & 512 === 0 // BOAT passable
flag & 1024 === 0 // SHIP passable
flag & 2048 === 0 && flag & 15 === 0 // AIRSHIP can land
This might assist too

Yeah, that's the post from which I took your quote 😀
haha - I missed that. Just on lunch so didn't read all of the posts.
Thank you for helping, everyone! I'm closing this thread since I think all the answers needed have been posted!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/help-understanding-passability-datamap-data-and-datatileset-id-flags.133448/