How to Use Tool Scripts and Resources in Godot (Godot Retro Text Adventure Tutorial #9)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we're going to learn how to use tool scripts in godot so that we can actually have our room ui update in real time as we change variables so instead of a house i could type house that something you could type a house that you don't recognize et cetera but it'll update in real time so we're going to learn how to use tool scripts in order to provide a really nice user interface and we are going to change our room dictionary our exit dictionary to use exits as a resource so we're going to create a new exit resource talk about how to use resources and then change our command processor to look at these resources to make exits really cool and easy to expand later on so we can make locked exits for example so you see here if i say go east it works just like we did before but now it's working using a resource for an exit that connects two rooms it's gonna be really cool and i'm really excited about this one let's get started okay so the big thing that we want to do in this video is actually beef up our exits so that we can customize them a bit more maybe we can say they are locked maybe we can say they are one way but we just want to create a foundation that makes it easy later on for us to adjust specific exits and give them more characteristics rather than just a two-way connection between a room before we do that though in the last two videos i talked about our room ui here there is a reason i made these panel containers rather than just a resource or something that didn't really have a visual component to it and the reason for that is because i wanted our editor to really display in an easy way for us to tell what our current game world look like i talked about this is one of the advantages of using a visual editor and engine like godot over versus or versus a you know code specific game framework and so we really want to lean into that and i didn't actually we didn't actually talk about how we can make that happen how we can make whatever the variables we set here for our room name and description in the editor actually show up visually for this component itself you know we've got a house room and an outside room that are different but they both look the same in the editor and so what we want to do first is fix that so the way that we're actually going to make our room ui components update when we change the variables is by going into our room scene so i can just click either a house or outside room and hit this open an editor button and now that i'm in our room scene i'm going to open our room script and the way we're going to do this is by making our room script a tool script so let me just give you a very basic overview of what a tool script is so in godot the godot editor itself is actually a godot game so just let that sink in for a second the editor itself is a godot game that is running on the godot engine what this means is that godot lets you have a really amazing level of connection to the editor itself from your scripts that's why everything works together so well and what that means is that we can actually define scripts that run not only in our game when we run it by hitting command b or control b but actually run in the editor as we're developing our game and you can imagine how useful a script that runs in the editor might be when we're trying to do something like this when we're trying to update our room ui component here based on the values we set on this right side over here for our room name and room description variables and so because that's what we want to do we're going to use a tool script here to actually make that happen and so all you need to do to make a tool script work or to turn a script into a tool script is just add the tool keyword at the very top of the script so i'll start a new line and just type tool and as soon as i save this instantly this code is now executing in the editor for each scene that is a room scene in our game now some quick notes because tool scripts run in the editor you can do some somewhat damaging things to your game so if you're cueing nodes free or freeing nodes freeing memory or deleting things you can you can sometimes mess things up or crash your game if you're not careful you want to be really careful not to free up memory or nodes or scenes that your game relies on and and do things that might mess up your scene tree so just be aware of that because tool scripts are running in the editor they are open to doing things that might cause some damage to your game now just because they're a little risky doesn't mean we shouldn't use them they're an incredibly valuable part of the ghetto engine but it's just something to be aware of now that we have our tool script this code this script is executing in the editor but the problem is that nothing's actually happening because we don't have any functions that are being executed we have this connect exit function but this only runs when someone calls it however if we use some of godot's built-in functions such as the processor ready functions those will run in our editor so if you define a ready function for example when you run your tool script or when you add that scene to your tree in your editor that ready function will run and you might be asking well if i've got a ready function and i have stuff that i want to happen only in the game but not in the editor but i still want to make this script a tool script how do i make that work and it's a great question and godot provides a way for you to run code only in the editor or only in your game and by only in the game i mean when you run your game from the editor or you run it from an executable because you've packaged up and shipped out your game and we'll go over that in just a second but before that just an overview of what a tool script is so i hope that kind of makes sense again feel free to ask questions in the comments below or join our discord if you're struggling with tool scripts they can be a little bit confusing but i hope that's just a general overview that gets you a bit familiar with it so because this is now running in the editor let's think about what we want to do here if i go to our game scene basically whenever i add a new room scene i want to be able to change our room name and room description and have those changes reflected in the editor here right now i've got our outside room selected and you can see that it's got um well it doesn't have anything right now but you can see that it's um if i were to give this a name like you know a house you'll see that if i save that it doesn't actually change what's in the editor the ui doesn't change and so us as developers aren't really helped by having this here because it doesn't immediately just show us what our game map looks like so we want to change that so in order to do that we need to tell godot somehow that whenever these variables change our room name and room description whenever they change we need to update our room name and room description labels because remember we have access to these labels right here so since it's a tool script the code's already running we just need to actually hook into those the changing of these variables and in order to do that we're going to use the setget functionality built into godot now get is a keyword that's or a concept that's familiar to a lot of different languages basically what it means in godot is you can define a set function in a get function you can do only one or you can do both you don't have to have a set and a get you could just do a set or just do a get and what it means is that if you have a set function whenever this variable is changed it doesn't matter where from whether it's from the editor or from another piece of code running in your game it doesn't matter whenever it changes your set function will be run instead of just changing this variable itself same thing for your get function from the editor or in your game whenever someone tries to get this variable your get function will be run instead if it is defined the syntax for doing this is to say set function so we say set get like you have here and then you give the name of your set function we don't have one yet this is just a default value so this you don't you don't literally type set function but you would replace this with the name of your function and then comma get function now like i said the set and the get are optional you have to have at least one but you don't have to have both if you wanted to have both you would define it like this but let's say we just wanted the set function i would get rid of the get function name and the comma and now whenever someone tries to set room name this set function will run but if they try and get room name it will get just the straight variable itself it will not run a get function however let's say i wanted to have a get function but no set function i could get rid of set function here and then just type comma get function and this empty comma means there is no set function but there is a get function i think the syntax is pretty ugly thankfully it's going to be a lot better in godot 4 when we have annotations it seems like that's the current path that the godot core developers are going down anyway this is a lot i hope it makes sense again feel free to ask questions but hopefully this gives you just enough familiarity with set and get to use them in our case we don't really care about getting room name we can just return the room name itself so we don't need a get function we do want a set function though so i'm going to call make a new function called set room name and i need to actually define this name here you'll see that the setter function isn't defined i'm getting this error down at the bottom because i'm saying this is our set function but it's not actually defined so let's make it now i'll create a new function i'll just copy it in set room name and we need to give it a variable we we know that the variable that comes in is going to be the new value for this variable and because this is a string so is our parameter that comes in here so i'm going to say new name and this is going to be a string and what we want to do is two things one remember that we want to change our room name this label's text value to actually be our new name so i'm going to do the dollar sign which is how we get nodes or scenes in our scene tree and i'm going to find room name right here and if you don't get that autocomplete there like you just saw me have remember make sure you're on your room scene you only get auto complete when you're actually you have the scene open that the script you're working in is attached to so now that i've got room name it's a label remember so i want to get the text property and set this to be new name so this is going to work except for one major issue which is now that we've defined a set variable here room name this variable is not going to be changed by default we need to actually make sure we explicitly change the value of room name as a variable within our set function so here we're changing the value of the label we need to actually change the value of the variable itself so i need to say room name and this is going to be equal new name so here we're saying hey whenever we change our room name from the editor because again we're not really changing this from our game we're only going to be changing our room names from the editor so whenever we change our room name call this set room function and within this update our room label to be the new name and update the variable itself to be the new name it's kind of a lot trying to explain all this quickly but hopefully in a way that makes sense let's actually see this in action now to make sure it's working so if i come back to our game and i select our house room here and i update our name if i say a house we'll see it actually changes in the editor which is amazing all of a sudden we've got a really great way to just change this one value here and it'll not only change in our game but in the editor itself i can do the same thing with our outside room and we can say outside the house and again all of a sudden we are we've got this value that is updating and now within our editor we can totally see the map of our game itself of our text adventure so this is incredibly helpful for you developing a text adventure game you can instantly see your map and again if we ever gave a viewport where the user could see this they would instantly have kind of an overlay they could see the game map as well you won't have to implement a separate map on top of your game already as it exists now we've done our room name but we have not done our room description so let's do that now if i go back to our room scene so hit this open an editor and then i hit our room script we can do pretty much the same thing with our room description so i'm going to add a set get and this will be set room description i'm going to copy this name just like i did before come over here again we'll see the setter function is not defined error which is good that's how we know godot is working as we'd expect and i'm going to say new description as the parameter for this function because this is not the name it's the description i'm really going to kind of do the exact same thing here so if i start typing room description we'll see it pop up again dot text and i'm going to set this to be the new description so here we are getting our room description label we're getting the text property on that label and the reason we're doing that is remember this is that text property we're changing this is what we want to change not the label itself just this text property and once we get the text property we are updating the description or the text to be our new description however though remember just as above we're not because we're using the setter function we aren't updating our room description anymore so we need to explicitly update that variable so i'll say room description and this is going to be new description okay so now that we've done that i should be able to go back to our game and we'll see our room names have persisted so when i click on these we see our room names have persisted they're still a house and outside the house now if i change the description we should see that also update so i can say a random house that you've never seen before anyway so we've got our room now and we've seen that we update when we update our room description it updates on here and if i click back and forth and switch scenes it persists so if i save this we see that our room name and description persist which is really amazing it's all of a sudden we've made this so much easier for us as developers i can do the same thing with our outside room so we can say you are outside of the random house in the middle of the village again we can make actually good content for our game later right now excuse my poor writing one thing you might notice is that a room description is kind of hard to read because it's a lot of text in a small field and one really cool thing about godot if i go into our room script again is that you can actually provide some more editor hints to tell it what type of export variables there are so this is not actually defining what type of variable the variable itself is but it's telling the editor how to display that exported variable to you as a developer and one thing that it allows is there's a a multi-line flag that you can give it so this room description we want it it'd be really nice if it was a huge text box a multi-line text box and not just like a single line thing so what we can actually do is after string here in our export hints i can make a comma and then do multi-line just all caps here and this is one of many available editor hints or export hints you can give the godot engine there's a whole page in the godot documentation about export hints i highly recommend you looking it up i'll try and include that in the description for this video but now you'll see if i go to our house room or house game or our outside room or house room you'll see that this is a huge text box now which makes it way easier to edit we could do the same thing for our room name but i think they're generally going to be short enough we won't but just wanted to show that that's a way that we can make our editor or developer experience a little bit better by making our room description string our text boxes multi-line rather than just single line wow that was a lot of work just to get our ui updating but now we've got that going forward which is going to make editing and adding new rooms and and changing their values really really easy so i hope you're tracking i hope that's been a good intro to both export or to tool scripts to set gets and you're starting to see the value of using an engine like godot even for simple games like a text adventure because of the really awesome functionality it gives you right out of the box so now that we have spent all that time getting our export variables working now we can actually start working on beefing up our exits a little bit and making them better so if i come into our room script again by just selecting the script button in the editor here on our house or outside room so we've got exits here it's a dictionary the keys in that dictionary are strings the values are rooms right we're setting our exits of east so a string to self which is a room so we've got string keys and room values now what if we replaced our room values with values of a new object or a new type of class or type of script we created called exits and within that exit it had the room exited too but it also had other properties like is locked is one way etc you can expand on it with whatever properties you want i think that would give us the best foundation going forward it would be the easiest to customize and i think it would be better than just having the room itself so we're going to do that we're going to create a new exit something an exit class object reference whatever now as we consider that we need to think about what that will be like what we want our exit to be um eventually we're probably going to want it to be visual right so we can hook it into our little map here we want it to be represented visually but it's going to be a little complicated so i think to start off we don't want to do that so no visual component on our exits right away eventually again i hope we'll get to that but so if we don't want a visual component we're kind of left with three options so this is one of the options but everything in godot that appears in your scene tree is a node right but in godot you might not know that you can actually create scripts that are not attached to nodes in your scene tree you can actually create scripts just like any other any other language or really like any other object oriented language because scripts are usually class-based and so we have three options if we want to create a type of object that does not exist in our scene tree that is not tied to a node object and those three objects are and i'm going to list them in order from most basic to most complex they're all pretty simple and basic but we'll start with the most basic so three options the first is object object is the base class for pretty much anything in godot and objects are not reference counted you have to manually memory or wow you have to manually manage the memory for an object so if everything that uses a given object is deleted then that object will be floating out in space but still taking up memory which is not good so objects are manually memory managed that is a lot of m's so i don't think we want to use an object because we kind of want to take advantage of godot's built-in memory management so objects are the most basic but manual memory management so we're not going to use those the next thing which is slightly more complicated are references are a type of class and godot that inherits or extends from object but they are reference counted so in godot if you have a reference object for example and it is referenced by multiple different nodes or scenes or whatever and all those scenes are deleted godot will automatically delete your reference as well because it has no more actual references to anything else so references are one step above an object and that godot will automatically take care of deleting a reference if everything that actually references it references that reference is deleted so references are a little bit better than an object typically in godot you really only want to use an object like the base object class itself if you really know what you're doing typically if you're just trying to make the simplest script class possible you want to use a reference but both objects and references i think are not what we want to use in our case even though references are a much better match than an object so those are our first two options the third option is a resource and resources are really cool and one of my favorite parts about godot you can think of resources somewhat similarly to scriptable objects in unity it's not a one-to-one comparison there are some differences but i think that is a comparison that is very that will make it much easier for most people to understand what a resource is and so what a resource is is one it is reference counted so it is similar to a reference in the sense that if everything that uses a given resource is deleted that resource itself will be deleted so godot will handle the memory management for you which is super nice we want that but the other things that make resources really really nice are that one they can use signals so we can may have a resource with a script attached and have signals attached to it that our other nodes and other scripts can kind of make use of or that resource itself can respond to signals so that's really powerful but the other thing that's really really nice about resources is that they are automatically serialized by the godot engine so for example if we made our exits be resources we could very easily save our exits just as resources we won't have to do any editing to them we could just automatically save our resources our exits and it would save whether that exit was locked or unlocked for example we wouldn't have to manually if we did like a reference for example we would have to save our do some custom saving logic and then re-instance upon loading those references and then manually set the locked property for example to be locked or unlocked with a resource that gets saved right into the resource itself you don't have to manually load it in and then do some logic on top of that so i hope that comparison makes a little bit of sense it's kind of hard to do without a visual aspect to to kind of do that comparison on your own but i think out of all those three options the object the reference and the resource the resource is going to be our best option and it's just a really good chance for me to kind of walk you through how to use resources in godot since they're one of my favorite things about the good old engine so all that to say once we've now that we've considered all three of those options i think that our resource option the resource is the best option for our exits and so that's what we're going to use right here to make our new exit system okay so we're going to use resources that's all well and good but how do we actually do that well so glad you asked the first thing we need to do is make a new script so in order to do that i'm just going to right click on our in our file system tab here right click and hit new script now you'll notice there's a new resource button again this is one of the really amazing thing about resources is that they become something that's easy to add and re-instance or create new new instances of resources within the editor itself but we'll get to that in a second i'm going to hit new script and i'm going to call this exit.dg so now we've got i created it we've got an exit.gd script i'm going to have to double click on it to open and you'll see it's extends node right now now we don't want to add our resource or our exits to our scene tree so there's no reason for it to be a node right now so i'm going to change this to not extend node but instead to extend resource and i'm going to get rid of all the boilerplate here now that we have our script here we can just edit it like any other script that is attached to a node except it's attached to a resource so what are the things that we need our exit itself to have the first thing we need is just to put what room it connects to so i'm just going to say variable room and we'll just leave it for that for now i'm going to actually type it as a room and we'll just set it up to be null at the start not knuck and then we can add whatever other properties we want the only property i want to add right now is just whether it's locked or not so i can say variable is locked and we're going to default this to be a boolean so i'm just going to say colon equals and we'll say false this will just tell it that it's a boolean by default it'll default to false and we've got to manually update is locked and later on we're gonna have to do a bunch more stuff with this like actually adding okay if it is locked what object does it need um in order to be unlocked but for now we'll just we'll keep it simple and now that we've got this what we can actually do in our room so we've got our our exit here what i'm going to do is add a class name to it similar to like what we did with the room so i'm going to class name exit now that we've got our basic exit class set up here let's talk about one other cool thing about resources i think i mentioned this before which is that in godot if you instance a resource for the first time or load a resource for the first time every other time that you try and load that same resource in godot will detect that it's already loaded and instead return a reference to that resource so it will prevent you from loading in the same thing multiple times or creating multiple instances of the same resource now there's sometimes you want to override this you do want multiple instances of the same base resource but godot by default will take care of that for you and it's pretty easy to override that let's say like if you're making an rpg and you've got items for example and you want multiple items that are the same resource you can pretty easily set it to be to create new or unique resources on each time it loads it in but by default it won't do that and the way that we've kind of got it set up now if we think about our exit dictionary that we have in rooms is we've got it where it's creating the same exit for both rooms so we've got our house and our outside for example right and if we want to go east from our house we have an exit that goes east to or from the house we've got an exit that goes east to the outside and then from outside we have an exit that goes west to the house so we're kind of creating two things when we really only need one and so one thing we could do with a resource for example is make each resource be a or each exit make be a two-way thing so the house going east and the outside going west so these could both reference the same resource and each exit could just keep track of which room it has on each side and so we can maybe try doing that for example so instead of just having one room here we could have for example we could say room one and this is going to be kind of arbitrary so there's going to be some things that we're going to need to change but i can say room 2 for example and we can say room 1 is locked and do the same thing here so i can say var room 2 is locked and set this to be false and now we can have our each exit can determine whether each direction is locked or not again if you want to do something weird eventually where you've got exits that can go to more than two rooms then you're that's more than just one room to another then you're gonna run into some trouble with this system but this is one example of we can actually cut down on the overall amount of stuff we have to create in our game by just using or just creating one exit resource whenever we connect two rooms so now that we've kind of got this basic this exit structure in place we've got our basic resource let's actually look at how we would implement this into our game so if i come back to our room script and we look at our connect exit function there's some changes we're gonna have to make here in order to make our exits work with our new resource system now remember that we made our exits be two directional so they remember both room one and room two so if i come back to our room script here now that we're here let's start actually implementing or adding in our new exit system and see how it simplifies this connect exit function here so now that we have an exit structure let's actually implement a new or instance in new exit and so in order to instance or create a new resource object which is what our exits are we can say var exit and then we're going to say equals and then what we can do is just say exit.new and so the new keyword is built into any type of resource or object or whatever it's all the same thing and we're going to create a new exit now we know that exits have a room one and room two properties so we can say exit that room one and this is going to be self right because we want our room one to be the self that's doing the connecting and we can say exit that room two this is going to be room which we're defining it's a parameter that's coming in and so whenever we connect and exit we're creating a new exit resource here and we're saying that room one is the self it is the room that is doing the connecting and room two is the room it's connecting to and all of a sudden we've got an exit variable here and what we can say is say exits of direction so this is this first line we've got we're so you notice we've got a lot of code duplication here right we're always saying exits direction equals room well we can just say that up here actually just so whenever we do this exits of direction equals room um sorry exits of direction equals exit because remember we're not storing rooms anymore we're storing exits and so for this room the exit in that direction is this exit resource but the real power of using resources remember the reason we made a room one and a room two is because we can now use this resource to connect both ways we're using the same resource for both sides of the exit connection and so one we can get rid of all these exits that direction equals room lines so i'm gonna get rid of all these now we still need this match here because we want to just as a convenience way to automatically connect certain elements so west automatically connects to east and vice versa north to south and north to south and vice versa but instead of connecting or creating a new entry in the other rooms exits for east for example that leads to a room we want it to lead to the same exit we just created right so we're going to change all these to be exit instead of self and so now what we're doing is we're saying so let's say for example real example here that we've got this is our house right and we're connecting our house to our outside well our house of east is going to be an exit where room one is the house and room two is outside and the direction here is going to be east so room one the house connects east to outside then we're saying that that other room outside connects to the west to this same exit object so we're using the same exit object or exit resource for both sides of the connection it's going to be the same thing being referenced on both the east and west side of this connection between the house and outside and it's going to happen automatically so we still keep the really nice feature where we only need to connect rooms from one side to the other but it's going to automatically work and only use one resource to make that connection okay so this is kind of complicated and i'm not saying this is the best way ever to do this but it is memory efficient and it's going to let us do whatever editing we need to to these actual exits going forward we've made a really nice architectural decision that's going to let us have maximum customizability for these exits as we want to going forward the only thing we need to do now is actually change our command processor so that when we move between rooms it's actually looking at these exits instead of just the room itself okay so we've got this and it's it should be working but the problem is that we haven't actually we've updated our exits dictionary here instead of having rooms it's having these exit resources we've created and we haven't actually updated our command process to work with these so our game's not going to work but let's just try and run it and see what happens and you're going to notice that we get this parser error saying the classroom was found in global scope but its script can be loaded i think this is an issue we've already dealt with which is the problem of cyclic dependencies and so if you go into our errors here you'll see this uh these two errors here saying room is already being loaded it's cyclic reference and so this is one of the problems unfortunately with godot as it stands now is that we can't have these um our types uh can't reference each other because from room we are referencing our exits here our exit cannot then reference a room again because it makes a circle from room to exit and back to room and then to exit et cetera and so it causes an error with an editor so unfortunately we have to get rid of our room typing here in our editor and just have them be non-typed variables for now and so now if i go back to our room and try running this game we'll see that it works it's not going to work the way we want to if i try going somewhere we're going to get an error but we've at least got something good enough that our game runs and we're ready now to edit our command processor and start making it work with our new exit system so now that we're looking at our command processor it's important to remember that for our rooms we didn't actually change what our keys in our dictionary were those are still strings that correspond to directions what we've changed are values so in our command processor we shouldn't need to update anything where we're looking at the keys in our exits dictionary really just the values and if you look at that you'll notice that in our go function we are looking here at the keys when we're determining if if an exit is valid and um same and change room here we're looking at our keys to join so there's really only one place that we are actually looking at our values and that's on this line line 35 here where we're looking at the exit the value of exits uh for a current room if we've determined that we've entered in a valid direction for our second word so here is where we actually need to get the um the room itself because right now when we index into our exits dictionary like this we're actually going to return and exit so we actually need to get the room but here's the problem with the way we've implemented this again i'm not saying this is the best implementation but i think it's it's better than what we have and we're making it better but there is one problem with it and that's how do we determine if we are in room one or room two and the reason i called it room one and two instead of left room and right room or west room and east room is because we want it to be generic exit structure we don't want it to be tied to a west and east room for example but the problem is we have to determine which side of the exit we're on or if we're on the the room two side then when we find the exit we need to go to room one and vice versa so we've got to add some logic right now to do that determination for us now we could add that logic into our command processor but i think that logic is intrinsic to an exit and exit should be able to tell us which side of itself we're on which side of the exit we're on and so i kind of want to add a function to our exit script that'll do that so in order to do that let's add a new function and i'm just going to say this will be function we'll say get exit and so it'll take a room we have to pass in room again remember because of the cyclic dependencies we're not going to type it here unfortunately here's hoping that godot 4 will have a better way to do that i really want something side note similar to like what you can do in typescript or many other languages where you can just have type declaration functions that exist outside of the function where those types get used so you could have like a static types file that other functions could actually just pull in and so there's not a cyclic dependency because you've just got your own type file somewhere that is getting used across the board it's not always the best in uh situation or best solution to problems but it would definitely help here and it would be nice to be able to find classes or types in godot or in gd script like that but that's an aside and just a little rant there do love me some typescript but okay so we're going gonna get the exit here what we need to do is say um if room equals room one and we're gonna do really simple boolean logic here for this we're not gonna use a match statement we'll just use a couple if else's because we only have two conditions and i'm not sure a match can actually match on a object rather than a primitive type i know we can do arrays and dictionaries but i don't know if we can do like a note or resource itself so i could be wrong but i think it's just easier to do an if else here so we'll just do if it's room one do something and then we'll say alif room equals room two you can see where this is going and we need to have a special case where if neither of them match we can do something else so we need to print out an error here it's like print air we can do so this is the case where we try and get an exit for a room but the room we're in is not actually on either side of the exit that we're currently looking at this should never happen but in case it does we need to have some error handling here so we can say the room you tried to find is not connected to this exit and you can give you can give whatever error message you want here but just something to say like hey if you see this you need to look in our code and we need to figure out what went wrong and so what we need to do here is remember we're going to be calling this from our command processor so we're going to be calling it from the current room that we are in and we need to find the other room so we'll be currentroom.exits.getroom or getroom to go to something like that actually we call this getexit let's call it get other room because we're trying to get the other room on this exit so if our room is room one we want to return room two and if it's room two we want to return room one now again this is we could simplify this a lot we could use a ternary operator but i think the reason i want to do that is to explicitly have this print statement here we can also just return null here as well and so now we know that we are going to return the other room and so what we can do is we actually have to get this exit now and we can call this get other room function so what i'm going to do instead is change this up a little bit so i'm going to say var exit and this is going to be we're going to grab pretty much the same thing that we have here so what are we doing we're going to get our current room and we're going to get the exit associated with the direction the second word so this is now going to be an exit and from within this exit we need to say exit.get other room because remember this exit is going to be one of our exit objects and the function we just made is get other room now we need to pass a room in actually i'm going to call this current room just to make it a little bit more clear that this is the current room that we're in so let me just change these real quick okay so we are passing in the current room and getting out the other room so that means when we call this function here in our command processor we also need to pass in the current room thankfully we do have the current room it's just the variable current room that we're keeping track of in our command processor so i can just pass it in as current room okay so now we should have not only a new exit system that uses exit resources which again are going to be easy to serialize so let's say we have a locked exit eventually and then the player unlocks it we can actually save that exit in its current state as now unlocked so that when we load it in it's automatically unlocked and we don't have to do that logic so we've got resources for exits that connect two rooms and we've now updated our command processor to actually get the correct room for the other side of the exit we're currently looking at okay so if i run it we'll see all right we are in a house as we'd expect and i can try go west again this should throw an air because it's not a valid exit so that still works and if i go east we'll see we are now outside the house it is outside of the random house in the middle of the village all right so this all looks good so far let me try go east again just to make sure i can't go in an invalid direction now if i try going west we should see we are back in the house and we are we are now in a house a random house you've never seen before oh man guys this was a long video we covered a lot of stuff again a lot of complicated things because we're just trying to make a system that is going to be really easy for us to expand upon later but sometimes that means doing a lot of the hard and complicated work up front so thanks so much for sticking with it i hope you've enjoyed this video and learned a lot if you did enjoy this video a like and subscribe is very helpful it supports the channel and helps it grow and was much appreciated we'd love to have you on our discord if you have any questions about the video link to that is in the description below and if you found my work helpful you can donate a coffee and buy me a coffee link to that also in the description below that helps me continue to make great and free tutorials for you thanks so much for watching everyone appreciate it hope you've enjoyed the video see in the next one you
Info
Channel: jmbiv
Views: 1,434
Rating: undefined out of 5
Keywords: godot, godot engine, godot 3.2, godot tutorial, godot 2d, how to make a game in godot, game development, game development tutorial, game development for beginners, godot for beginners, game dev, how to godot, godot game engine, godot text adventure, godot text adventure tutorial, godot text, godot input, godot user interface, godot control node, first godot game, godot beginner tutorial, godot resources, godot tool, godot resource tutorial, gdscript, godot tool keyword
Id: w_6rtbReRgw
Channel Id: undefined
Length: 40min 54sec (2454 seconds)
Published: Mon Apr 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.