Tsukihime 1,487 Posted May 16, 2012 (edited) Tile Swap Author: Tsukihime Overview This script allows you to easily change tiles on the map. Download Get it at Hime Works! Tutorial: Easy Tile Swapping. I would recommend reading this to see how this script works. Examples: Making a bridge A crack in the wall Credits KilloZapit, for providing the code for auto-tile generation. Usage There are three types of tile swaps 1. Change by tile id -All tiles on the map with the specified ID will be changed to a new tile tile_swap(old_tileID, new_tileID, layer, map_id)2. Change by region id-All tiles that are covered by the specified region ID will be changed to a new tile region_swap(regionID, tileID, layer, map_id) 3. Change by position-The tile at the specified position will be changed to a new tile pos_swap(x, y, tileID, layer, map_id)]You can undo changes by using the following calls tile_revert(tid, layer, map_id) pos_revert(x, y, tid, layer, map_id) region_revert(rid, layer, map_id) revert_all For performance reasons, you should avoid swapping tiles by ID. It goes through every tile on the map to see if it needs to be changed, and if you have a large map, it will take some time to perform. This is meant for large-scale tile swaps where it is unfeasible to specify using regions or positions. It is recommended that you stick with region tile swapping and position tile swapping. Understanding tiles This script uses the concept of a "tile ID", which is a special string that represents a particular tile on your tileset. The format of this tile ID is a letter, followed by a number. The letters available are based on the tileset names A, B, C, D, E The number represents the ID of the tile. So for example, "A3" would be the the third tile in tileset A, whereas "B12" would be the 12th tile of tileset B. An example usage would be tile_swap("A9", "A1", 0) Which will swap all "A9" tiles on layer 0 with "A1" tiles. As usual, because I did not pass in a map ID, it is assumed to be the current map. Please check the new script call format for details. It is very easy to look up the appropriate ID: just look at your tileset and number the top-left tile as 1. Then, numbering left-to-right, top-to-bottom, you would get something like this For tileset A, it is a little different. This is assuming you have all 5 parts in tileset A. You will need to skip over any missing pieces appropriately if you do not have all 5 parts. To avoid all this unnecessary math, simply fill up the empty slots with dummy tilesets to make things easier. Edited March 2, 2015 by Tsukihime 1 Gump reacted to this Share this post Link to post Share on other sites
Shablo5 8 Posted May 23, 2012 (edited) It took me a while to understand SwapXT, how similar to that is this? How about user friendliness? Does it do less/more than SwapXT Did? Also, with the ability to switch tiles based on the tileset available in maps now(Default in ACE), do you feel that this is still necessary? I can see how it would be necessary if like, a crazy event happened and it changed everything, then you'd have maybe a lava/burning-esque tileset requirement, but other than that..? Thanks. Edited May 23, 2012 by Shablo5 Share this post Link to post Share on other sites
Tsukihime 1,487 Posted May 23, 2012 (edited) These are just in-game script calls. You have to understand how the tilesets are put together (see images), but other than that, it's pretty straightforward. I'm not sure how swapXT works. Edited May 24, 2012 by Tsukihime Share this post Link to post Share on other sites
Rave 14 Posted June 28, 2012 Cool! Can someone change it into animated tiles script? So we can set "animation array" of tile ids? This way we could make animated tiles without wasting characters (and since characters support either 3 or 4 frames per animation, depending if you use rotations or "normal" static animations we would have more frames of animation) and events. We just could place tile on map and script would do the rest. Config would be like this: Anim1 = {5,3,4,6,7,3} Anim2 = {8,7,3,7,5,3} anims = {Anim1, Anim2} # array of animation arrays animsets = {"C","E"} #arrays of tileset letters for specified animations. If invalid (must be "A" to "E") or missing, E is assumed Share this post Link to post Share on other sites
Tim 23 Posted June 28, 2012 When I'm home this evening, I'll send you some code I have that deals with autotiles, might help a bit. Share this post Link to post Share on other sites
Tsukihime 1,487 Posted June 29, 2012 I remember seeing some auto-tile code in a random dungeon generator, but I couldn't figure out the pattern. It was a massive set of conditions to determine exactly which ones to use lol I'm guessing you figured out something while doing your own dungeon generator? Share this post Link to post Share on other sites
goshisanniichi 0 Posted January 22, 2013 (edited) Great useful script. Helps me get around some of the limitations of a script for mode 7 that I'm using. Although I have noticed some errors in how your script handles tiles with transparency, (layer 2, b-set), I've tried it with the mode 7 script disabled, so I'm certain it's not the problem. The image I'm using for examples for this post are on Google docs, so the links are to the images. This image is after a swap has been done on a layer 2 tile, I intentionally chose a tile that has lots of transparency to better show what happens. https://docs.google.com/file/d/0B-UFkq51k1uIZl9lMy1vRGt0dE0/edit In the following two images, I made it so that the normal "unswapped" tile was the broken bridge and the swapped it with the unbroken bridge. (The tint in the before image is from a simple event-based day/night algorithm.) Before: https://docs.google.com/file/d/0B-UFkq51k1uIYnVqa212MElndjA/edit After: https://docs.google.com/file/d/0B-UFkq51k1uIaEZ2QW9LVmEzZXc/edit JIC, this is the script as I'm calling it: pos_swap(111, 53, 104, 2, 6, 12) Unfortunately my skill at coding is at a very Basic level (both literally and figuratively), so it's beyond me to be able to even begin to suggest how to fix this. But aside from these little issues, this script is pretty awesome. EDIT: BTW, the first part is because I tried removing the layer 2 tile altogether and using an initial autorun event located on the same map as the player start to put in the broken bridge. That way I could use a later event to again call your script to remove the tile of the broken bridge and the call the script again to insert the tile of the intact bridge. Edited January 22, 2013 by goshisanniichi Share this post Link to post Share on other sites
Tsukihime 1,487 Posted January 22, 2013 Send me a demo with the tileset set up so that I can quickly test any changes. It looks like I might have gotten the layers wrong. Share this post Link to post Share on other sites
Tsukihime 1,487 Posted February 17, 2013 (edited) I have updated the script with auto-tile updating based on killozapit's auto-tile generation code. Now it looks a lot better. Currently, it simply checks every tile, but that is unnecessary. It would be better to simply check any changes tiles, and any adjacent tiles to those changes tiles, because changing a single tile will only affect at most one direction of an adjacent tile. I will be revising the script usage and try to make it easier to use. Edited February 17, 2013 by Tsukihime Share this post Link to post Share on other sites
Tsukihime 1,487 Posted February 17, 2013 (edited) I have revised the entire script. Please be aware of the following changes. The changes were made in order to increase user-friendliness of the script. 1. The input tile ID is now a string composed of two pieces of information: the tileset as a letter, and the ID as a number. "A7" would be the 7th tile in tileset A "B2" would be the 2nd tile in tileset B "C4" would be the 4th tile in tileset C An example usage would be tile_swap("A9", "A1", 0) Which will swap all "A9" tiles on layer 0 with "A1" tiles. As usual, because I did not pass in a map ID, it is assumed to be the current map. Please check the new script call format for details. 2. It is very easy to look up the appropriate ID: just look at your tileset and number the top-left tile as 1. Then, numbering left-to-right, top-to-bottom, you would get something like this For tileset A, it is a little different. This is assuming you have all 5 parts in tileset A. You will need to skip over any missing pieces appropriately if you do not have all 5 parts. A1 starts at 0 and goes to 15 A2 starts at 16 and goes to 47 A3 starts at 48 and goes to 79 A4 starts at 80 and goes to 119 A5 starts at 120 and goes down to the last number To avoid all this unnecessary math, simply fill up the empty slots with dummy tilesets to make things easier. Edited February 17, 2013 by Tsukihime Share this post Link to post Share on other sites
A holy Templar 0 Posted February 28, 2013 yo no offence tsuki but this is hard for me i like doing stuff with events Share this post Link to post Share on other sites
Tsukihime 1,487 Posted February 28, 2013 This is pretty much eventing. Share this post Link to post Share on other sites
+ Crossroads 12 Posted February 28, 2013 nicely done. very useful for invisible tiles (to allow passability without putting a ton of events all over the screen) Share this post Link to post Share on other sites
Velvela Jade 8 Posted March 4, 2013 (edited) I'm trying to use Tile Swapping to make a sokoban game. (Rules of Sokoban is posted last). What I am attempting: Using Tsukihime's Tile Swap to make a Sokoban game. 1) Player uses Choices, they can move box anywheres they like, which is not what I want. I know I have to use player variables some how, but am not connecting with how to do that. When[LEFT] Script: pos_swap(042, 025, "B118", 1) : pos_swap(043, 025, "A157", 2) When [RIGHT] // etc. // includes UP and DOWN, with pos_swap. Original question solved --> FYI: using Get Location Info in Ace, does not give a good location of where spot on map is. Its off by quite a bit. LOL This was why code wasn't working at all. If I delete that Get Location Info code, then I can get the box to move. With it in, it doesn't work. Thanks! Sokoban rules: Player can push but not pull box. Box is to be pushed to marked spot. In my case, its the purple tiles with the black background. Edited March 4, 2013 by Velvela Jade Share this post Link to post Share on other sites
Tsukihime 1,487 Posted March 4, 2013 (edited) I am not sure what the issue might be but firstly 058 is not the same as 58. Ruby treats them as two different types of numbers (octal vs decimal), and octals go from 0 to 7, which is why 058 gives that error. Correct the numbers and see if that will help. Edited March 4, 2013 by Tsukihime 1 Velvela Jade reacted to this Share this post Link to post Share on other sites
Velvela Jade 8 Posted March 5, 2013 (edited) Tsukihime said: I am not sure what the issue might be but firstly 058 is not the same as 58. Ruby treats them as two different types of numbers (octal vs decimal), and octals go from 0 to 7, which is why 058 gives that error. Correct the numbers and see if that will help. ________________________________________________________ I was using the number that "Get Location Info" game me, and it gave me 054. To get box to move from 054, 032 to 054, 033, I have to use decimal, or the box won't move. (It actually gives a number that is 8 tiles to the left and 5 tiles up from where mouse actually chose.) 1) Solution: To get the player to not be able to pull the box, but instead only be able to push the box, I found this option: Conditional Branch: Player is Facing Down (or facing in which ever way box is too be pushed). That solves the issue. FYI: Sokoban is a game where the player attempts to move boxes through a series of challenges in order to get them in "storage". They have walls in the way, hallways that boxes can't go down, and other boxes in a the way. And, they only allow the player to push a box. There is no do over if you push a box into a dead end. You can't pull the box. If you have never played Sokoban, then this may be confusing. Question: What script do I use to prevent Box (tile B118) from being moved to a spot where another Box already exists? Thanks! (using chrome and apparently, it adds crap html to posts and bans smilies! Chrome is bleeping stupid! I deleted all the crap, but can't guarantee it will stay gone. ) Picture: Edited March 5, 2013 by Velvela Jade Share this post Link to post Share on other sites
Tsukihime 1,487 Posted March 5, 2013 (edited) If you're using events to move the boxes you can always check whether there is already an event at the destination. It would probably be better if you made a separate thread for figuring out how to implement your system since most of it is not really related to tile swapping. Edited March 5, 2013 by Tsukihime 1 Velvela Jade reacted to this Share this post Link to post Share on other sites
Shayneareus 0 Posted March 22, 2013 I have been doing everything exactly as followed and properly but when I trigger the event I just get an error like unknown method "region_swap"?Im quite new at most of this, so please can somebody help me understand why I get this error ? Share this post Link to post Share on other sites
Tsukihime 1,487 Posted March 22, 2013 Maybe you can post a screenshot of your event. Share this post Link to post Share on other sites
Shayneareus 0 Posted March 22, 2013 (edited) This is the event, I just have the script in for the region which is across the bridge on the right. Edited March 22, 2013 by Shayneareus Share this post Link to post Share on other sites
Tsukihime 1,487 Posted March 22, 2013 It looks like it should work. Did you paste the script into your script editor? Is it above Main and below Materials? Share this post Link to post Share on other sites
Shayneareus 0 Posted March 22, 2013 Okay well I just pasted it under materials and above main, but now when I try to test it it wont load at all and will give me another error. is there a certain way it should look when pasted in? Or how should I have it?I know I'm probably a hassle but I really need to learn how to do this Share this post Link to post Share on other sites
Tsukihime 1,487 Posted March 22, 2013 Upload a demo through dropbox or mediafire or something so I can see how your project is set up. It can be a new project with just that script. Share this post Link to post Share on other sites
MrCrunchwrap 0 Posted April 11, 2013 Tsukihime, I love your script but I am having some issues with it. I am trying to make food appear on a table, using the default interior tileset. Right now, my script reads like this: pos_swap(20, 11, "C38", 2) C38 should correspond to a birthday cake, but I instead get the tile from B38 every time (the top half of a little window). Any idea what might cause this? Share this post Link to post Share on other sites
Tsukihime 1,487 Posted April 11, 2013 (edited) Looks like I only wrote the calculations for the A page, and didn't do anything about B C D or E. So when you wrote 38, it wasn't offset appropriately depending on the page, and 38 is located on page B. I have updated the script to address the bug. Thanks for the report. Edited April 11, 2013 by Tsukihime Share this post Link to post Share on other sites