Easy tile swapping

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,230
Reaction score
3,082
First Language
English
This tutorial goes over the Tile Swap script that I have recently revised. Some new changes have been made that make the tile swapping process very intuitive and easy to use.

Required

Tile Swap

Introduction

There are some concepts and terminology that you would need to be familiar with

before effectively using this script.

Tilesets in Ace

RMVX Ace's tileset design takes a single tileset and splits it into 5 different

tileset pages (A, B, C, D, E). It then takes the A-page and breaks it down

into 5 more parts (A1, A2, A3, A4, A5)

Tile Layers

There are three layers that tiles may be placed: 0, 1, and 2.

0 is the bottom-most layer, while 2 is on the top.

In general, pages A1, A2, A3, and A4 tiles are drawn on layer 0 and 1, while pages A5 B, C, D, and E tiles are drawn on layer 2.

Depending on the draw-order, you may need to specify which

layer a tile should be drawn on.

Referencing Tiles

This script uses a custom concept of a "tile ID", which is a special string

that represents a particular tile on a tileset page.

The format of a tile ID is a letter, followed by a number.

  • The letter is the tileset page.
  • The number is the position of the tile on that page.
So for example, "A3″ would be the the third tile in tileset page A, whereas"B12″ would be the 12th tile of tileset page B.

A fast way to calculate the position is to use the formula

((row - 1) * 8) + column
It is very easy to look up the position of a tile: just look at your tileset page and number the top-left tile as 1. Then, numbering left-to-right, top-to-bottom, you would get something like this



For page A, it is a little different. This is assuming you have all 5 parts.

If you are missing any parts, you will need to skip them appropriately.

To avoid all the unnecessary math, simply fill up the empty slots with dummy tilesets to make life easier.



Example

Now that you understand how tile ID's work, here is a working example.

In the oasis map, I want to reveal a hidden staircase at the bottom of the oasis



This means that I will need to swap the water tiles with some sand tiles, and then add some stairs.

1. Get the tile ID of the water tile in (row 2, column 3, so ((2 - 1) * 8) + 3 = 11)

2. Get the tile ID of the dark sand tile (row 4, column 1, so ((4 - 1) * 8) + 1 = 25)

Both tiles are in tileset page A.



The script call I want to use to swap all water tiles with sand tiles is

tile_swap("A11", "A25")Now I want the staircase. It is in page B, near the bottom.


I would need to specify where the stairs will appear. I can choose to use a region swap or a position swap. In this case, I will use a position swap

If you read the documentation, you will notice that I have a "layer" parameter.

Tiles on pages B, C, D, E should appear on layer 2. If you are not sure which layer things should be on, just remember that autotiles are usually on layer 0 or 1, and everything else is on layer 2. In fact this doesn't really matter THAT much but if you run into strange tile issues it might be a layer problem.

I want the stairs to appear at (21, 27), so the script call would be

pos_swap(21, 27, "B223", 2)Now I want to add some plants at the bottom of the oasis. I will use a region swap to swap in one of the plants in page B to any region 10 tiles.


The plants I want to use are "B89", on layer 2, so the script call would be

region_swap(10, "B89", 2) Finally, I create an NPC that will perform these script calls


And now I can test the final results





All tile properties are swapped, such as passage settings, terrain tags, damage floor, etc. so can walk across the sand.



It might be nice to fill the oasis with water again. Since we made several changes, it would probably be easiest to just revert everything.

revert_allA more appropriate method is to revert each specific change

Code:
tile_revert("A11", 0)    # we changed A11 to A25, so now we want to revert changes to A11 on layer 0pos_revert(21, 27, 2)    # reverting changes on position (21, 27) layer 2region_revert(10, 2)     # reverting changes to region 10, layer 2
Talking to the NPC would "put" the water back into the oasis



By combining all three different types of tile swapping modes (tile ID, region ID, position), you can make interesting changes to the map dynamically and easily.
 
Last edited by a moderator:

ShinGamix

DS Style 4Ever!
Veteran
Joined
Mar 18, 2012
Messages
3,907
Reaction score
450
First Language
April Fools
Primarily Uses
N/A
I was thinking i didnt need this but after reading through the whole example it could come in handy!

-Does the passiblity change with the swap tiles also? Meaning can you walk on the sand now?
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,230
Reaction score
3,082
First Language
English
Yes, this is a full tile swap, and not just changing the appearance. Whatever properties you have given to that tile (passage settings, terrain ID's, damage tile, etc.) will be swapped.
 

ShinGamix

DS Style 4Ever!
Veteran
Joined
Mar 18, 2012
Messages
3,907
Reaction score
450
First Language
April Fools
Primarily Uses
N/A
so could i use this to make a bridge appear and walk over it?
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,230
Reaction score
3,082
First Language
English
Yes. you might do something like


Making a bridge


1. Add regions for each bridge tile





2. Swap them appropriately





Result





There are many ways to do it. You could use position swapping as well.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,230
Reaction score
3,082
First Language
English
Crack in the wall


Setup your smash event and the tile that should be replaced with a hole.


I used a pos_swap event since I am only changing that one position.








 
Last edited by a moderator:

Baka-chan

☆*:.。. o(≧▽≦)o .。.:*☆
Veteran
Joined
Dec 19, 2012
Messages
490
Reaction score
147
First Language
German
Nice script, might use it for stuff like building a fence or hidden entrances :3
 

GrandmaDeb

Modern Exteriors Posted!
Veteran
Joined
Apr 25, 2012
Messages
4,468
Reaction score
2,921
Primarily Uses
So essentially, you are using this tile set swapping script to replace blocks of events or additional maps for large changes, right?
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,230
Reaction score
3,082
First Language
English
So essentially, you are using this tile set swapping script to replace blocks of events or additional maps for large changes, right?
That would be one use, yes.

It provides finer control over how you want to manage your map, and most importantly it gets around having to deal with *other stuff* on the map.

If you have a river in a city with a hundred events and a whole bunch of switches/variables going on, you are probably going to run into issues if you transfer to a new map just to empty out the river. Plus, duplicate events is poor practice: if you make one change, you're going to have to remember to make the same change to all of the duplicate events. Not much different from duplicate functions in programming.

The engine comes with a "change tileset" event command, which allows you to change the entire tileset.

This script provides a "change tile" event command, which allows you to change individual tiles.
 
Last edited by a moderator:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,008
Reaction score
11,345
First Language
English
Primarily Uses
RMVXA
The engine comes with a "change tileset" event command, which allows you to change the entire tileset.

This script provides a "change tile" event command, which allows you to change individual tiles.
For which I am very grateful, as I can think of somewhere in my game where this will save me a lot of trouble.

Thanks
 
Last edited by a moderator:

numbuh1

Warper
Member
Joined
Jan 25, 2013
Messages
1
Reaction score
0
First Language
vietnamese
Primarily Uses
pos_swap(x, y, tileID, layer, map_id)]
I want to swap the tile at the player's X and Y coordinates, can you show me how to do it?
 

sporadicus

Warper
Member
Joined
Feb 20, 2013
Messages
1
Reaction score
0
First Language
English
Primarily Uses
Is there a wait command, so you can make the draining of the pool (or the crumbling of a wall) area by area?

I imagine it would be something like setting a separate region designation to each set of tiles you want to be changed out at a certain time, with a wait script in between (maybe a second half second wait time).

Does anyone have any ideas about the wait command?
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,230
Reaction score
3,082
First Language
English
For the wait command you go with this. Use pos-swapping or something with wait commands in between.



I can't think of a more efficient solution.

Some sort of "area" swap might be useful as well, where you specify the position along with a width and height (eg: 3x2 rectangle swap), but I will have to think about how to implement that.

I want to swap the tile at the player's X and Y coordinates, can you show me how to do it?
Code:
x = $game_player.xy = $game_player.ypos_swap(x, y, tileID, layer, map_id)
 
Last edited by a moderator:

Demilux

Warper
Member
Joined
Apr 16, 2013
Messages
3
Reaction score
0
First Language
Croatian
Primarily Uses
I apologize ahead if I'm doing something basic in a wrong way, but I constantly get this error when using your script:

"Script 'TileSwap' line 131: NoMethodError occured.

undefined method `upcase' for 65:Fixnum"

I tried it even on a project where I use no other scripts, yet it still happens when I try running the event that's supposed to swap tiles.

This is what I have written in the event script "region_swap(001, "A98", 1, 001)".

I also tried using other types of swapping, yet they all result in the same error!

Thanks ahead!
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,230
Reaction score
3,082
First Language
English
I'm unable to reproduce the issue. Are you using the most recent script?


Post a demo.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,230
Reaction score
3,082
First Language
English
This script is for VX Ace. I don't know if it will work with VX or not.
 

Demilux

Warper
Member
Joined
Apr 16, 2013
Messages
3
Reaction score
0
First Language
Croatian
Primarily Uses
I sincerely apologize for being so blind and somehow not seeing it's only for Ace! Sorry for taking your time away, but still, thank you very much for trying.

I apologize once more... :)

Do you think, though, there may be a chance of adapting it for VX? It's a brilliant script, I'm sure it would be of use to many.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,230
Reaction score
3,082
First Language
English
No, since testing in VX is too slow for me cause having to start it up takes like 10 seconds, but someone else can do so if they want.
 
Last edited by a moderator:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,008
Reaction score
11,345
First Language
English
Primarily Uses
RMVXA
When I use this script in playtesting, I end up with one of 2 problems.

If I put the script call for a region swap exactly as above, i.e region_swap(10, "B89", 2) then when I click on the event nothing happens.

If I put a space between region_swap and the bracket (which is what I did in error the first time) then I get the error message

Script 'Game_Interpreter' line 1411: SyntaxError occurred

unexpected ',', expecting ')'

region_swap (62, "D243", 2)

Apart from that difference of the space, I cannot see how my formula differs from the example. 

Similarly, when I use position swap, I get the error message:

Script 'Game_Interpreter' line 1411: NoMethodError occurred

undefined method 'upcase' for 0:Fixnum

Can anyone tell me what I'm doing wrong?

Thanks
 
Last edited by a moderator:

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

Latest Threads

Latest Profile Posts

Karen: Hi, I have a condition that prevents me from wearing a mask. :)

Employee: Can you tell me what it is?

Karen: >:(
Feeling a little overwhelmed... There are so many things to do.
- Building a simple website for portfolio
- Setup *******
- Manage social media
There are so many things inside of these tasks :(
Meet the cute little ghost, FhooFhoo. :kaopride:
If anyone here is looking for another high-potential RPGMaker game--besides She Dreams Elsewhere--be sure to follow Lawmage Academy. Good social media presence will take that game far.
Lol, I was about to write a small tutorial and realized it would belong to the MZ section ....that does not exist yet.

Forum statistics

Threads
99,574
Messages
966,813
Members
131,232
Latest member
Bektos
Top