 This video went out one week early on library library has almost everything I want in the digital content platform It is this centralized open source peer-to-peer with a backend running on a blockchain with cryptocurrency incentives That's why I'm truly supporting this project the library team humbly offered a nice gift for this community a hundred coupons to claim a hundred library Credits they cryptocurrency is not much But is enough to get the feel out of how library works for instance It is enough to get new teaser there. So you can use the cupo code Big dev library in their reward system to get access to this gift If you don't know how this works, I will show you how you can redeem this code at the end of this video. That's it Let's get started It's very common when we are developing a game that we make a lot of mistakes And we need to be fast when we are fixed them so we stay productive to be really fast We can automate repetitive tasks through programming in Godot engine one way to do that is by using editor scripts So in this video, I will teach you how you can use this powerful scripts by making a tileset tile fixer So we have this very simple scene and what I want to do is to change these styles here These on the edges of these platforms. So these tiles are the Grass nine and by the way, if you want to have these tileset I have a asset pack that uses Kenny So these tiles are from Kenny and this asset pack is a bundle of more than 800 assets from Kenny, but ready to use in good engine So you can get them through the good old sandbox pack I will put the links in the description, but I want to change here this style to this one So the grass nine and I want to change them to the grass four So let's make a tileset fixer a tool that will do that automatically for us because Let's be smart and not waste time doing repetitive tasks The first thing that we need to know about editor scripts is that we can just like create and attach them to a node So what we will do first is that we'll go to the script workspace And we'll create a file here. So let's go to file new script and instead of inheriting a node We will inherit editor script and let's save this editor script in the root folder But I will name that tile fixer So let's create the script and the first thing with a third scripts is that since they will work in the editor We need to make them to scripts. So let's add the tool keyword right at the beginning and Another thing is that since they are not attached to a node and we won't use like ready or process callbacks Instead editor scripts, they have the run virtual function that is called when we go to file and Run and when we do that it will run the current opened editor script So let's go back to our editor script We'll take rid of everything here and instead we will add the run method and just so you can see how we can execute the script I will print executing and since we Actually, we do have a scene open. I will close the scene but if we don't have any scene open we can save the script by going into Save and you can see that there is a shortcut for that control out as and I will run this script So I will go into run and in the output. We can see that we have executing already So let's clear clear that and I will execute this again and you can see that this is executed So let's clear that again and let's now think about how we can achieve what we want with our Editor script so first things first, I will pass that and what we actually want to do is just Overwrite one tile by another right, so let's create two constants here There's the target tile and for now, let's say zero This will be the index of the time that we will override and next we'll create a constant another constant And this will be the desired time and let's say one just for the sake of having something into this constant And now we can start working with the logic of our of our script the main advantage of the actor scripts So if we open the documentation for that I will hold Control and click on actor script is that we can have access to the actor interface So the actor interface is basically the class that will represent the actor interface of the growth engine And through that class we can have access to a lot of interesting parts of the engine with the editor of the engine One of these is the editor selection So if we open that that their selection is basically a class that will represent what is being selected now So we can have access to selected nodes and why this is interesting It's because if we reopen the scene so I will open the sample level scene if we select like the level We can have access to this level if we select two or more nodes We can have access to all the selected nodes and what we'll do is that we will access that array So get selected nodes will return an array and we'll try to see if what is inside this array is a tile map So let's go back to the tile fixer and let's start by getting the actor Interface so actually we can get the selector already. So the selection already so selection will be equal to get Editor interface dot get Selection and then we will get I will try to access the array of the selected nodes that is inside this selection So let's create selected nodes, which will be equal to selection dot get selected nodes So if we print that and if we save our script and run it You see that we have the tile map and a node 2d. So this is right what we have selected But we don't want to have like multiple nodes selected or maybe we want but in this case We will try to get only one selection and this selection will be the tile map So for that we can use like a some exclusion logic first things first Let's check if this selected nodes since it is an array we can check its size and see if this is greater than one So if selected node size is greater than one, we will not work with that We don't want multiple node selected and also since we don't have an array with more than two node selected Meaning that it is greater than one. We can get the first node of this array So the first index of this array and check if it is a tile map, right? So that we can make sure that we are working with the right thing So if the first thing is not a tile map So selected nodes first index of this array is not a Tile map we will also return we don't want to work with that and if this passes So if it passes through this test, we want to fix these tiles So we'll create a function. Let's call this functional array fix tiles and we want to Inject a tile map here to this fix tiles method. This will be like an injection of the dependency So other classes, so like if we have a plugin or something like that We can also execute this method in a different way. So we'll get let's create a Verbal that will be a time app and it will be the selected nodes first index and then we'll pass that To to this function and let's work on fixing the tiles now So let's take rid of this pass keyword and I will open the documentation for time app because we'll probably need it So the logic here is that we will go through all the Cells that contain this target tile that we want to override and We will try to get its properties. So let's go back to this time app So if they are flip it, we want to flip the new tile as well If they are not flip it, we don't want to flip it if they are transpose We also want to do that So if we go back to script and to time app There is a method that gets all the user tiles of a Specific index so of a specific ID of tiles get use itself by ID This is the method that we want. So let's copy that Contrucy tile fixer and what we'll do is the following so for Cell in the tile map The get use itself by ID and we'll pass this target tile So for every cell that is using this current ID in in in this case will be this target tile that we can change here In this constant, we'll do the following. We'll see if it is flip it So flip it X it can be flip it on X or Y and we'll see the following So there is a function in the time app that will return if this cell is actually flip it So if we go back to time app that is this is self-lipped is sell Y flip it and it's self-transport Let's try to copy all of this So is self-lipped and as far as I could see it doesn't use like a vector 2 We have to pass both index for X and Y position So we'll go to sell X and sell Y and let's do that for flip it as well Y axis I will just basically just copy that and just change this to Y transpose so transpose it sell X sell Y and time Now that we know how this cell that we are working with is currently so the properties of the cell if it is or Not flip it if it is or not transposed now We can override it with the new cell that we want so the desired tile to override the target tile and to do that We can use the function set cell V. I think that this is the name of the function So set cell and this will will need to pass the X and Y position But I will use cell V instead because I think that this stands for Set cell by vector and we can pass a vector and we will need to pass the tile and the flip X and Y and also the transpose so let's do that so time app dot set cell Vector will pass the cell directly and we will override it with the desired tile and let's pass the flip it X flip it Y and The transposed so let's save this So now we can test is if this is actually working, but let's See what are the the target tile and the desired part that the desired tile that we want to override So if we go to the tilesets grass tile we can see that the tile that we want to override which is this Grass nine. I think that it will be the index eight. Yeah the index eight So let's set this value to eight and the one that I want to use instead is this grass tile For and I think that it is only third index. Yeah, so let's set this to three And let's take rid of that save the tile fixer control out S and this is currently as it is and Let's run it Run and why it is working just as we wanted. So if we want to like change this again We can again change this Indexes here. So let's say we want to go back to what it was So I will basically just a switch this control out save control out S and Run it again and it went back to what it was, but I don't like that So I will change this to what I want and run it and there that we have it Now note that this is just the bare bones of what an editor script can achieve So for instance, I have some other samples scripts here And one of them is this tile fixer, but also I have an offset fixer for tracks of an animation this will offset some of the values of a position position for instance and also I have some factory scripts For instance, this is an audio stream random pitch generator This will basically take an ODD file and will create an audio stream random pitch resource with that So this is what I used to automate some of the Tasks of the sandbox the good old sandbox that I just showed you with 800 SS implement I wouldn't implement a manually I just made some scripts that will generate some files for me and I run them then for instance for the sound effects I think that there were 300 sound effects and I just made a script like this and I just had to run it once and it did the job for me So that's it. I hope this helps you be more productive with your game development And if want to get more like on tool scripts or more on like being productive white game developing Leave a comment below so I know what you want to know about and how I can help you So that's it. Thank you so much for watching keep developing and until the next time So to redeem the coupon that library gave us you first have to create your own account on library for that You can use the referral link that I will put in the description this way I will also earn some library coins with that and after you create an account you will have to go to the library You can use either the library desktop or the library web interface to do that and from there you can go into these Numbers here. This is the current amount of library credits that you have and if you click there You can go into rewards and from here. You have to find Custom code. So here is where we can enter a custom code. So we can enter one and Here you can see that I already claimed mine. So now we only have 99 of these coupons. So if you enter a big dev library here And then you can click on redeem and then you can claim your coupon. So that's it