[Ace] How to modify map tiles using script call

Example case:
superherolanding.gif

Q: Alright, but can you just do that by using tile event and flip the switch or just change the graphics and it solves the same problem?
A: You can, but then you add more events. More event means extra process and may cause lag, and also makes your game looks messy in the back end.

General thing you need to know.
We are going to make a change in tile B to E on your map. So you need to know that each tile has its own ID.
Started from tile B, from the left-top, the ID is 0, to the bottom-right, the ID is 255.
Then goes to tile C, it started from 256 to 511.
Then tile D, it started from 512, etc, you get the idea.

What are these IDs tell us? And how are we going to use it?
You can access the ID by using this script call.
Code:
$game_map.data[x, y, 2]
X and Y are the coordinate positions of the map.
The number 2 means it's layer 2, where the tile B to E is placed.

Another Example Case:
We are going to add objects surrounding the player. I'm going to use default world map tileset as an example.
Here is what we are going to do.
spawn.gif

And so this is what I did.
tilechange.jpg

The coordinate adjacent to the player will be changed.

However, do note that the change will not be saved. So if you leave the map and re-enter, all the changes made by the script will be gone. You will need an extra effort to make the change is saved. But I think it's better for someone to make a script for that.

I guess that's all for now! 😀

Author Notes
  • I'm honestly not sure how useful it will be. But I think better tell everyone how to do the trick then it's up to their judgment how to use it.
  • For fun, you can actually place tile B in the first layer by doing $game_map.data[x,y,0] = 1 but doing so will eliminate ground tile.
  • If you have no idea what number a certain tile has, you can place that specific tile somewhere, and run a script call "p $game_map.data[x,y,2]" and open console log (Of course you have to change the [x,y] into the real number of the map position). It will print the number of that specific tile.
  • You can actually make a change of the auto-tiles/Tile-A, but the number is more complicated.
Hey, thanks for the tutorial
May I ask you if we can modify the map using another script?
Hey, thanks for the tutorial
May I ask you if we can modify the map using another script?
Elaborate pls
to store the change map, you'll need more than this simple tutorial - you need a full script that modifies loading the map.
Tsukihime's tile change script is one example for such a script.
This is certainly useful for temporary changes, I think especially with cutscenes.
Very nice tutorial and a good presentation of tile IDs. I will try experimenting a bit with this during the weekend. Like @Engr. Adiktuzmiko mentions, I think it will work wonders for cutscenes. I think I am going to replicate your first example as a lead-in to a boss battle!
I just realized that adding this code isn't necessary as it's already in the default code. I wonder how/why I missed it.
Code:
class Game_Map
  def data
   @map.data
  end
end
Removing it ....

Edit: Another sample use
collapsing bridge.gif
Hello @TheoAllen , so we can swap tile just like that. What about change those tile's passage setting too?
Hello @TheoAllen , so we can swap tile just like that. What about change those tile's passage setting too?
Passability flag is still beyond my knowledge. The number is even weird than Tile ID. But I will get there in the future, or at least, I believe.
Your tips are so awesome!
@TheoAllen I honestly think this is quite useful. I can think of quite a number of situations where you need something like this. Not to mention that I am a fan of using the lowest possible number of events to improve performance.

I have been swapping tiles instead of using events for a while and I am quite glad to see that you made a nice tutorial about it. This way whenever I see people using events that way I can provide them a link to this tutorial. 😀
don't you need a refresh after changing the tiles? or is that taken care at each scene update?

Passability flag is still beyond my knowledge. The number is even weird than Tile ID. But I will get there in the future, or at least, I believe.
it's a binary/hexx conversion.
if this is the tile's properties: 01001010, read as "0 to property 1, 1 to property 2, 0 to 3, etc", you turn that into Hex, and it gives you 48, so the tile's visible and stored data is 0x48.
reverse that and you get the lot of properties as a binary string, but you have to know what each bit corresponds to.
if you look into the passability checks in the code, you'll see each check passes down an Hex value and the coordinate, that Hex value when converted to binary is the bit to be scanned, so you binary AND or XOR (can't remember now) that against the full string, and it should return 0 or 1, meaning "this coordinate has THIS value 0/1".
it's a neat way of storing a lot of booleans in a small space.
don't you need a refresh after changing the tiles? or is that taken care at each scene update?
The data refresh is built-in by default.

it's a binary/hexx conversion.
if this is the tile's properties: 01001010, read as "0 to property 1, 1 to property 2, 0 to 3, etc", you turn that into Hex, and it gives you 48, so the tile's visible and stored data is 0x48.
reverse that and you get the lot of properties as a binary string, but you have to know what each bit corresponds to.
if you look into the passability checks in the code, you'll see each check passes down an Hex value and the coordinate, that Hex value when converted to binary is the bit to be scanned, so you binary AND or XOR (can't remember now) that against the full string, and it should return 0 or 1, meaning "this coordinate has THIS value 0/1".
it's a neat way of storing a lot of booleans in a small space.
This is an interesting insight. Probably to reverse engineering the bits gonna take some time, unless if there's already source I can read somewhere. Thanks!
RPG::Tileset, sub title "flags", Ace's help files.

a solid impassable tile would be written as
Code:
0000111000001111
|--|
15 terrain tags
    |-|
    impassable by airship/boats
       |---|
       no counter/draw on top/bush/ladder
            |--|
            solid in 4 directions
In short, if I wrote a flag that is "0x0140" means it's a tile that is a bush and does a floor damage?
maybe?
set everything to 0, change it by code, recompile, and restore the project, and it should be changed in the database.

EDIT:
yes.
solid yes.
I got confused because the scheme is 4-3-5-4, when the notation is 4-4-4-4, there's a bit that carries over from the counter/bush properties to the airship passability set.
Thank you! I can make a wall collapse in after a player solves a simple puzzle involving it

Original thread: https://forums.rpgmakerweb.com/threads/ace-how-to-modify-map-tiles-using-script-call.104491/