Change the terrain_tag at runtime

Did you try just running the two commands in the post above?
Of course. And it didn't seem to work. I changed the tiles on the map and than run $game_map.setup_surfaces and $game_map.merge_surfaces and nothing happend 🙁

I am quite certain that what you are suggesting is somehow possible. I just think that I am just not able to write that code. Especially because Khas Awesome Light Effects has no code documentation or some simple inline comments (aside from setup, licensing and such). So its not really easy to really get whats going on in the script.
The terrain tag read depends on the current tile_id at the location starting at the top-layer, the one you are modifying.

I.e. the terrain tag is change automatically when you change the map data.

I bet the problem is rather in Khas' Light Effect script. He probably scripted with the assumption that the terrain tag will not change on-the-fly.

*hugs*

 - Zeriab
I tested it with $game_map.terrain_tag($game_player.x, $game_player.y). The terrain tag doesn't seem to change with $game_map.data. It stays on its initial tag, at least in my case 🙁
This is a screenshot of the event that is changing the game_map.data:

[IMG]http://web490.srv1.sysproserver.de/guenters_stuff/Event.png[/IMG]

And here is what it looks like with Khas lights:

[IMG]http://web490.srv1.sysproserver.de/guenters_stuff/Lighting.png[/IMG]

If that helps...
That's strange. It worked just fine when I tested it. I did use the Get Location event command, but that just calls $game_map.terrain_tag(x, y) so I don't see how that should be any different.

Can you create a test project for me?

On a different note I suggest you make sure the map is not reloaded on saves when you have created any modifications. You can check my Map copy script for a solution to that problem.

*hugs*

 - Zeriab
It works in the test project as you said (without Khas script)..... problem must be somewhere else... thanks for the suggestion.
Here is a demo project:

http://web490.srv1.sysproserver.de/guenters_stuff/TerrainTagTest.zip

(Terrain Tag for players tile is printed to console window)

The problem seems to be only with roof tiles. The terrain tags for floor and wall tiles seem to get overwritten. But roof tiles will keep their initial tag... for whatever reason
Ok, making it work was actually quite fun ^^

Whether a specific tile is a roof, wall or block depends on the terrain tag. The terrain tag is refer from the top layer first (x,y,2) then (x,y,1) and down to (x,y,0) until it finds a non-zero terrain tag. You put a tile on layer 1 that had terrain tag 0, where layer 0 had terrain tag 7. So fetching 7 is to be expected.

The actual tile ids fetched are dependent on layer 0 so the walls you put on layer 1 is ignore then. Moreover autotiles have a significant impact. I.e. you may have to change the tiles surrounding the tiles you are changing.

Here is a link to the fixed demo: https://www.mediafire.com/?c1wckdq4q7q1xq1

I have added two methods to Game_Map which should help you. Call $game_map.map_data_change when the lights should be updated after changes to the game map data.

The $game_map.change_shadow_data(x, y, new_value) is used to simplify removing shadows from the game map while preserving any Region ID there might be specified.

I have been very specific with the autotile ids so there is work left generalizing those, but I hope this is enough to help you progress further on your own.

*hugs*

 - Zeriab
Wow, thanks A LOT. Wouldn't come to my mind that the layering was the problem -.-

I'll implemented it tonight and see how it works in the real project 🙂

I am aware of the autotiling problem. Doesn't seem to work at all at runtime. I found this pretty tile-ID sheet, which helped a lot: https://dl.dropboxusercontent.com/u/68527961/RMVXA/Tutorials/Autotile%20Data.htm#tileids5

And also thanks for your "copy script" suggestion!
Works like a charm! Thanks again for hacking that out!
nihilath, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.


Just edit your last post instead.
Good to hear that it works for you ^_^

Feel free to use my copy script as much as you want. My suggestion was aimed more specifically at my solution to preserving the map when loading a save.

This is the interesting part from that point of view:

### Change reload mechanism#class Game_Map  attr_accessor :data_modificationsendmodule DataManager  class << self    unless self.method_defined?🙂zeriab_copy_reload_map_if_updated)      alias_method🙂zeriab_copy_reload_map_if_updated, :reload_map_if_updated)    end     ##    # Reload must not occur when we have made any runtime data changes.    # Otherwise we may throw our changes away    #    def reload_map_if_updated      if !$game_map.data_modifications        # No copy changes so we are save to use the normal reload code        zeriab_copy_reload_map_if_updated      end    end  endend
With that you can simply use the following command when you have changed the map data:

# This map is no longer safe to reload when loading$game_map.data_modifications = true
Now when loading the game the changes should be preserved. Otherwise if you have done any changes in the editor since then the map is likely to be reset clearing what changes you have done.

Note: Leaving the map and coming back still clears everything.

*hugs*

 - Zeriab

Original thread: https://forums.rpgmakerweb.com/threads/change-the-terrain_tag-at-runtime.35315/