Create A Hidden Objects Game in Godot | Michael Mcguire | Skillshare
Drawer
Search

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Create A Hidden Objects Game in Godot

teacher avatar Michael Mcguire, Author | Programmer | Twitch Streamer

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

    • 1.

      Introduction

      0:38

    • 2.

      Downloading Godot

      1:58

    • 3.

      Creating Our Project

      3:20

    • 4.

      Scene Layers

      7:40

    • 5.

      Changing the Cursor

      11:47

    • 6.

      Collecting Objects

      10:17

    • 7.

      Visual Inventory

      8:40

    • 8.

      Saving and Loading Data

      8:19

    • 9.

      Loading Data to Inventory

      18:05

    • 10.

      Remove Objects From Scene

      8:45

    • 11.

      Draggable Objects

      16:02

    • 12.

      User Information

      7:19

    • 13.

      Map

      11:08

    • 14.

      Using The Map

      5:55

    • 15.

      Locks

      20:58

    • 16.

      Fixing Lock Signal

      8:44

    • 17.

      Alternative Options

      8:12

    • 18.

      How To Add Audio

      5:17

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

77

Students

--

Projects

About This Class

Learn to create games in the Godot game engine using a python-like programming language, GDscript.

In this course, we will create a Hidden Objects game that is cross-platform for MacOS, Windows, Linux, Android, IOS or even embed into a browser.

While on your game development journey you will gain the skills and ability to create the RPG you want.



You will learn:

  • The layering of Hidden Object games

  • How to move from one location to another

  • Save and Load data

  • Create a key and lock system

  • Inventory Management

    and more...

    Godot provides a huge set of common tools, so you can just focus on making your game without reinventing the wheel.

    Godot is completely free and open-source under the very permissive MIT license. No strings attached, no royalties, nothing. Your game is yours, down to the last line of engine code.

Meet Your Teacher

Teacher Profile Image

Michael Mcguire

Author | Programmer | Twitch Streamer

Teacher
Level: All Levels

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introduction: Welcome to my course. And in this series we're going to go ahead and you're going to learn all the core concepts to creating a hidden object games. So if that's something that you've been looking to create, our wondering how is done well, now you can learn how to do that. We're going to be making our scripts reusable so we can use them on multiple different objects all throughout our game. No matter how many scenes are, how many levels are rooms that you want to create. This includes collecting objects, draggable objects, key's locked, transitioning from one room to another, I keeping track of our inventory, saving and loading our data, and so on. So if any of that sounds interesting, come on over and enroll, and I'll see you in the video. 2. Downloading Godot: All right, Welcome everyone. That first step into starting our development of our hidden objects game is so of course, we get our engine. So if you don't have this end-to-end already installed, you can head over to the Godot Engine.org website. Hit Download here at the top. You're operating systems should be detected. But if not, you'll find both Linux, Mac OS, and Windows here at the top. And you'd go ahead and select the standard version. We don't need the mono version as we will not be using C-sharp during this project. And you can see some of the requirements down here currently is OpenGL support. If you have any machine here, you should pretty much be good to go. And then you have some instructions here which has C. We just, we're gonna get a zip when we download it. You just extract it and you're able to start running it. Alternatively. You can get through school. If you know how to do that. Cool. It's also available on over an inch. You can get it and download. And it is available through steam. Now if we go, so how you get it, you're going to need the export templates. Now you can either get it through here. And I'll show you how to install it in the next video. Or we can actually get it directly through the engine itself, which I'll show you how to do that as well. So if you want to get the final sum, so you can go ahead and click this button here, export template standard. And I'll show you what to do with that file. If you don't want to get the physical files here, then I'll show you how to get it from within the engine. So I'll go ahead and just go and download your version for your OS. And I'll see you in the next one. 3. Creating Our Project: Alright, when opening up and got 0 for the first time, you'll be greeted with this launcher of sorts. And as you may have as a popup, it might ask you if you wanted to download a bunch of the demos. If you do, you'll see all of these within here. And if not, well, it's no worries. None of them are really going to help us for our project in this course. But while we're here, we can go ahead and hit New Project. You can go ahead and give it a name. I'll call mine hidden objects, puzzle game. So I'll call my that you decide where you want to put. I'm just going to be minus I the documents. I'm going to hit Create Folder. And I'm going to use OpenGL ES 3 if you watch this in the future and you're using Gatto 4, this works. We'll instead save Vulcan. All right, go ahead and hit create and edit. All right, now let me just adjust this so you can see everything on screen. All right. And we have our first project setup and ready to start working on it. But what we're gonna do, as I told you last time, that I'll show you how to get the export template is going. So we're going to head to write on a peer to editor and come down to manage export templates here at the top. Now, if you downloaded the file, you wouldn't install from file and you will locate that file that you downloaded. And if you did not download the file when he wanted to do it from within the editor here. You can go ahead and say download right here, hit that. And then you'll have this URL link here, this hyperlink and saying official, whatever version you're on, stable HTTPS. Let's go ahead and click that and your download will begin. And once it fully downloaded, you'll have the templates. And so now we need these templates and R2 actually export a project. So if you just want to use this to practice your coding and learn a bit, you can do that, but if you want to export your final result, result at the end, you'll certainly be able to do that now. All right, so we have our project ready and raring to start going. I'm going to head over to 2D. And I'm going to change if it thinks I'm gonna go to my project settings. And here under the General tab, I'm going to scroll down on the left until I find the Windows section is we under display window. And I'm going to turn these around my height and width. So I'm gonna go with 600 by 1024. And I'll close it. All right, So I'll be using a portrait view for our first project here and working with this. And that'll be it for this video. And I'll see you guys in the next one where we can start getting into things. I start making up our hidden object games, bring it in our assets and starting our code. 4. Scene Layers: All right, everyone, in this video we're going to go over our layers and set up our scene so we can start learning the simple concepts. And, you know, it's kind of block out the core of a hidden objects game. So to do that, we're going to need to start off with a 2D scene. Of course. We're gonna go ahead and I'm just going to change the name of this from no 2D to main. And you can just right-click and rename or double-click it to do that. And to start off going to go ahead and save. So I can keep this same. But the sudden my scenes folder so I can keep everything together and organized. Hit Save. All right. Now if we go into our Textures folder, you're going to see we're going to have our initial image as well as something that's this top layer picnic. And both of these are going to be what allows us to hide and show our objects around. So if we just go ahead and grab our full image here and just place it on in here. Something like that. And we go and you'll see that we now have a full image. It doesn't suffer. Interesting, it's just kind of there, but that's fine. Because we also have another image here, our top layer picnic. Let's go ahead and drag that in as well. And just try and line that up as best as you can. If you would like, you can click on the first image and look over to the right-hand side and open up transform. And you could check those numbers there and you can go ahead and copy those and put them inside the transform of your top layer. If you would like to get them exact. And with that, we have our two layers of our image. So as an example, I'm going to go ahead and just drag in this bear. And if I were to put this bear and my hierarchy in-between them, you see I can now hide this bear behind the bush or behind this bush or for whatever reason down here, behind our little pillows. So that top layer is what's going to allow us to hide our objects around in our scene. Now, obviously this bear would need to have its own theme for this. Because we need more than just a picture here. So I'm gonna go ahead and delete that, delete the bear. But you can see the kind of structure that we're going for with this. So I'm going to hit the plus at the top here to create a new scene. I'm going to hit other node because I want this to be a sprite for my base year. And I'm gonna go ahead and rename that to bear. I'm going to bring in the texture for it. And I'm going to hit the plus up in the top-left to add a child node, I'm going to add in an area 2D. And with that we're going to add in a coalition sheet. Now the collision shape selected, and we're going to look over to the right side into our inspector. And for shape, we can just select new rectangle. Now, you can go ahead and just enlarge this to fit. We don't have to be any pixel perfect because this is pretty much just going to be more like our clicking area than the area that's going to affect our mouse and tell our game what to do. I'm gonna go ahead and save if you want to know the shortcut and we're just using Control S. And we're going to just leave this as named a bear scene, put it in our scenes folder and hit Save. Now you can go ahead and do this for your other objects as well. So I'm going to create another scene. Go to other. Suck my sprite. I'm going to name this one camera. I want to hide a camera in my scene. We're going to add the area to D and our collision shape. I'm going to add the camera texture to my sprite. Collision shape. We'll add the rectangle. And in this case the angle is a little off, so you could just go big enough like this to cover it all. Or if you would like. But you could do is move into transform and just adjust your rotation a bit to kind of fit a better. Either way you want to do is completely up to you. Let's see. Oh, you wanna go the other way? There's negative 10. Look like negative 10 looks pretty good. Probably close enough for this. And we'll just go like that. Make sure we cover up our camera and save that as our camera scene. And now we have a two objects and we can start hiding in our game. Awesome. So in our main scene, and we'll go ahead with main. A main selected with what looks like this chain icon at the top. And what that does is that allows us to add in scenes that we have already created. So we can go ahead and add in our bare click Main again, and add in our camera. You can just grab both of those, put those in-between of our two layers. And you can begin to position them, positioning them wherever you would like. I'm going to place my bear there and I'm going to place my camera hidden down here. Now, my camera for this scale looks really big. So I'm just going to go ahead and shrink it in. And as you see, we have this like Free Transform. But if we hold shift, we can keep that aspect ratio. So I'm just going to go ahead and shrink that down. Adds kind of took that in behind the pillar here. All right. Bear things can lift that up there a little bit. That looks like it's a big bear. So I'm going to just go ahead and shrink that down a little bit. All right, so now we have a bear and we have a camera, and we have them hidden within our scene. Now, you know, ease, place this anywhere you would like. You can always modify this top, this top layer. And if you want to create other pieces that you want to hide, you can definitely do that. And as you will see, if I just hide my bottom layer, all I did was just cut out chunks from that image and just use that on a separate layer in order to hide things behind it. And then we just position it like this so that it's looks indistinguishable like it's one piece. All right, so we have those all set up. Hopefully you have an understanding of how our layer system works in our hidden objects came here. And next we'll move on to setting up our visible inventory area and start getting our scripts going. 5. Changing the Cursor: All right, welcome back everyone. In this mirror, we're gonna get our mouse setup with our cursor to be changing around whenever we hover over an object. Because if we go ahead and hit play or now, we need to select our main scene. We can select main scene. And you see when we're here, nothing happens, we have no indicator. And if you want your game to be like that and not really have any indicator to help out your user. You could do that. However, I would recommend having some sort of indicated not what your player doesn't get too lost or bored with what they're doing. But that'll be completely up to you and type of game that you want to create it. Obviously, if you don't change your mouse to games, going to be a little bit harder, especially if you're not telling them what to look for specifically. So I'm gonna go ahead and close that. And just down here, I'm going to select scripts folder here. I'm going to right-click and I'm going to create a new script. And I'm going to call this global. And this is where we're going to hold a bunch of different information. Now up two projects, project settings, we head over to auto load. We hit this little button here next to path directed to our global script and hit Add. Now what this will do is add as a singleton. And that means we can access all the data within here from anywhere in our game. Let's go ahead and save that now if we double-click our script here, and the left-hand side, we can see our script here opens up. And we can begin. So what we're going to need for now is going to be two variables, which are going to be our mouse norm and our variable for mouse click. So it's going to show us what is clickable and what is not. And we can set each of these to a load. Load and we go, and inside of these parentheses, we're just going to drag in our mouse cursor. So I'm going to use cursor one for my normal. And we'll use cursor to for our clickable. And you'll see both of those errors go away once you fill those out. And for now, that's all we're going to need. I'm gonna go ahead and just remove this information. That's all we need. I can go ahead and hit control S, save this up. And we can begin doing a script for our objects. So we can do this anywhere. I'm going to go ahead and just go straight to my bear scene. And click on my bear and hit this Add Script button attached new or existing script. I'm actually not going to name despair. I'm going to name this object because we're going to be able to use this script on all of our objects, all of our collectible objects for our game. Alright, make sure that isn't in our scripts folder. This is in scenes. We don't want that. So we want to open this up, go back and select scripts. They're real. So we want read as colon slash slash scripts slash object, close objects. And okay. All right, so what do we need here? We are going to need to determine if our Here we go. We're going to need to determine if our mouse has entered an area. So we're going to do var mouse Enter. And we'll set that to false by default. Because by default we're probably not gonna have our mouse inside of an area. So we're basically not going to have our mouse on top of an object to start with. And what we need to do is we need to actually connect two signals. And this will be coming from our area 2D. So if you do rename your area 2D here on your bare, make sure it's the same name on your camera and all of your other objects for this. So we're going to dollar sign and we're going to get the area 2D. And we're going to connect. And inside here we can put in the signal we want to connect. And for us it is mouse entered all lowercase. Our next argument is the script want to attach it to, which is self. We just want to put it in this script here. And then the last one is the function we want to call when this signal gets emitted. Which reference is going to mouse entered? Now we also want to connect a, another signal for mouse exited. And we'll do the same thing for our function. Mouse exited, just like so. Now before we forget, we should create these functions. So what do func mouse entered? Make sure to put open-close parentheses on the end, followed by a colon. And on the next line we're just going to type in pass. And we'll get our next one created as well. There we go. Now we, we don't forget too, have these created. And if you saw what I did there, I went ahead and just double-clicked on my function name here. That way I can just copy it and paste it to make sure that I have it exactly the way I typed it the first time. Alright, so when our mouse enters, obviously mouse enter should be true because now our mouse is inside of the area. So let's go ahead and set mouse enter to true. And that means when we exit the area, we have to set it back false again. So mouse enter equal false inside of mouse exited. So hopefully you're following along. It's fairly simple to understand. I would hope when our mouse goes into this blue area, it tells our script to set it true to male-centered, to let our script node that our mouse is inside this area during this whole time. And when we take it out of the blue area, it'll be considered false. My bear, I think it's going to squeeze this in a little bit. It's a little too wide for me. All right. So now it should work, which is great. And if we want, we can go in and print two statements here. Inside of Mao center will say, and we'll just go ahead and browse smells preprint mouse entered. And when we exit, will print mouse exited. All right, let's go ahead and hit the play button and pay attention down here in your output console. And when your mouse goes in with the bear now centered and when we leave, mouse exited. So we can see that's working. Our signal is being sent. And the reason we don't have to emit this signal ourselves is because area entered or I'm sorry, mouse entered, a mouse exit. It is a default signal that is built into the engine for area 2D. Alright, so our mouse is working. So what we need to do now is worry about our mouse. So let's set our mouse by default this head up to project and go to Project Settings. Go to the general tab. And we can just look for our mouse settings. There we go. Under display, we have mouse cursor, ac custom image. Go ahead and open that up. Now again detectors and select cursor one. So that'll be our default image or default mouse now when we open up the game. So to change this, when mouse is entered and MSX need, we're going to use input dot set, custom mouse cursor, I. Then inside of this, we're actually going to tell it what, what we want it to be. So we had this actually on our mouse or to our, on our global script. So we can just do global dot mouse click. Now the reason why we can just use the word global here, if we go into project settings back to our auto load is because of your name here. If you wanted to change this to something else and say I'm maybe GB or yellow or whatever, you want to put it in there. That's the name you would use for where I'm putting global here. So by default, it will be the same name as your script. So global event dot mouse click, and that will call this mouse cursor here that we have loaded. I didn't. Likewise, when we exit and we want to set our mouse back to the way it was. So input.txt, custom mouse cursor. And we're gonna put in global mouse norm. All right, so that should work. Let's go ahead and hit the play button. And this is hey, big mouse here. And there we go. And we enter, we can clearly see it is now clickable. And it's obviously not going to work on a camera because the script is not on our camera and now it's only on our bear with a row. Now we have a mouse that changes and adjust. Now if you want to change the scale of this mouse and you can easily do that. You just have to go into our image and just resize it. But it's just easiest that, and that's no problem. Easy to do. Well, I do this. I might rescale my mouse a little bit here for this, but that's it. You know, uh, you now know how to change your mouse based on when it enters and exits. And we'll be using our variable mouse enter here for later when it comes actually clicking on objects. But with that, we now have a little bit of scripting. And here we have our global setup. Well, for now. And we can now go over to our camera, to our camera object here in our scene. And we can go ahead and add a script and you can either click on the Plus and navigate to the objects, or we can just grab objects dot td here and drag it up onto our camera. And now when we open it, it will also work on our camera. So we see it works on our bare and it'll work on our camera. All right, so we now know, now have our custom cursor setup with our objects. 6. Collecting Objects: All right, everyone, in this winter we're going to make our objects actually clickable. And we're going to add them to a contained a dataset I've collected items. So if we go ahead and hit Play, you'll see that I changed my mouse cursor, I adjusted it so now it's more manageable. It's half the size that it was and is a lot more normal looking. And we see it work, still works fine for both of these objects. All right, so to do this, we're going to have to go into our data script here, or sorry, into our global script. And we're going to add a new variable called data books. Data. And we'll set this equal to being a dictionary. Now a dictionary is set of data that can contain different types of data within it. So a dictionary could have a list in it. It could have a string, like you see here, which is items between quotes. It can hold numbers, it can even hold other dictionaries within it. An easy way to tell a dictionary from a list is a dictionary has the squiggly brackets, whereas a list, we have these square ones. So let's go ahead and we're gonna do a string here and we're going to call this collected objects. And it will set that equal to a pair of square brackets. Oh, my mistake. After our collected objects, we have to put a colon in here before the equals. And we actually don't have the equals there. My mistake, I was thinking about variables again. So, and so we have data for variable equals our squiggly brackets. And inside of that we have a pair of quotes that have the word collected objects between them, followed by a colon, and then a pair of square brackets. All right, So collected objects here is going to be a list as indicated by r square brackets, which is great. And that's what we're going to keep our, keep track of our objects in. We can go ahead and save that, that way we can access that easier. And inside of our object script, we can come on down and create a new function. And this is called underscore unhandled input. As you can see there, it'll pop up and it has event as being passed into it. Now, we don't have to use the sea vents, so it'll pop up with an error saying that event isn't being used. It doesn't hurt anything to leave it there. But some people do get a little annoyed that it pops up same with Delta in the process function. If you don't want that to show up, you can just put an underscore at the beginning and it will not pop up anymore. All right, on our next slide, we need to check if the left mouse button is being pressed. And we'll check to see if our mouse is indeed entered into that area. And if so, then we're going to perform our actual gonna do what we need to do whenever we click on an object. So let's go ahead and check if input dot is action. Just pressed. Now we don't have an action here, but for the moment we can just leave that open and we're saying and mouse enter double equal signs because we want to do a comparison is equal to true. Put a colon on the end. Now the next line would just hit pass. Now you'll see an error pops up on your screen saying too few arguments for his action, just press. And we can solve that by creating a Left-click action. So we go into projects, go to the input map tab for action. Let's create one called left-click and hit Add. And you'll see at the bottom of your screen we'll have left-click go and hit the plus button to the right, select mouse button. And left button is what we want to select an ad. And now for an argument inside of his actions just pressed, we can go ahead and do pair of quotes and you'll see left-click pop up. Go ahead and select that. And that'll get rid of the errors that we had. So what we're gonna do is we're going to add this into our collected lists right inside of our global script, that data that we just created. So to do that, we have to access it. So we use global dot and the name of our variable, which is data. And then what we're gonna do is we actually open a pair of square brackets. And inside of this we type in what we're looking for, which is going to be collected objects. That's the next level down. Collected objects, make sure you spell that correctly, and these would be exactly the same. And since that is a list, we can just do dot, append and open, close parentheses inside of this. Inside of these parentheses is actually what we want to add. So append, what that does is append will add an object into in-between these square brackets in our dataset. And it will just always add new item onto the end every time. That's what a Pandas append adds a new item. So what we want to add is self dot name. So in this case this'll get bear because our sprite that the script is honest can't bear for a camera. It'll get camera for if you had glasses. It'll get glasses, right? So whatever our object name is, that's what it's going to grab and that's what we're going to add to it. Now to make sure that our bear is always has a capital at the beginning because it looks nice, a lot nicer when we're looking at a set of data. We're going to call also called dot. Capitalize, open, close parentheses. And that's what's gonna make the first character of our name a capital. And it's just nicer look at and make sure that we do that even if we don't put it in our sprite name. So it's almost just like a fail-safe just in case we've forgotten. And of course, once we collect it, our objects should, should be gone. It should be disappeared, right? So we can go ahead and do that mouse, or we won't set in us. But we're actually call our mouse exited function because it's still a function, we can actually still call it normally. And we don't have to wait for a signal to be signed, we can just call it. And then we can do self dot Q free. And that will delete itself, making, making it disappear from our scene. Now, to make sure that this works, before Q, at using Q3, we'd actually go ahead and just print. And for an argument for what we're going to print is going to be our global data. And of course this is going to be our collected objects mature. You spell that correctly and you get your capital capitalization correct. And again, that should just work for a bare wire for a camera because we're keeping this as open as possible. So now we can mouse over our bare, our mouse cursor changes, click it. And we see in our console bear was printed, it disappear and our cursor returned to normal. And now if we go over to our camera, we see it changes here. And if we click on it, we'll see camera added to our list. And when it prints, we should see bare comma camera. Again with the first letter being capitalize, which saw some. It's working. We now have the basics of our little hidden object scheme here going on. Now what would be nice is if we had an inventory for a game that we could see, because maybe, maybe we're going to find something that we can use later on, such as a key or another object for maybe solving a puzzle or something, right? Maybe we ought to find an object and then returned to another section in our map and use that object to advance. So we'll take a look at adding in our item and little inventory, right? That we can see as well as adding our object down and into it whenever we collect it. All right, so you can go ahead and do you want to run that again? You can see everything still works. Camera bear. Bear camera. Doesn't matter which order we collected in. And it all just works. All right. I'll see you guys in the next one. We'll go over creating our little inventory setup. 7. Visual Inventory: All right, Welcome everyone. We're going to go ahead and create our little inventory set. When we collect an item, we can add the name of the item as well as a picture of the item so we know what it is visually and readily, readily when we read it. So we're going to click on Main in our scene, hit plus, and we're going to get what's called an item lists. And we can just move that. You can put on the side equal to 0 at the top, wherever you would like it. I'm going to put mine at the bottom of the screen. That looks like a nice size and I'm just going to pull it across. Now we can always adjust this later. I'm going to set this to mind to 10 columns because that's about what I should be able to get going all the way across would have a mild here obviously, if you have yours going along the side, it's going to be a little differently, actually only going to have one column or maybe two depending on how big your icons and not r. So we're gonna go ahead and now click on icon, and we're going to say Icon Mode to top. If you want to set your Select, you can. It's going to be a completely different layout. What that's gonna do is having top. It's going to have our image on top and then our text underneath of it haven't on the left. And we're going to have, I believe our image on the left and then our text on the right of it. So it's up to you how you want to do that. I'm going to set my scale to I think 32 or probably be good. We can see if we want to change that. And after we start adding items and do it. If you want to change the name of your item list to something such as inventory or collected items or something. You can definitely do that. I'm just going to leave mine as item list because that name tells me exactly what it is. It's a list of my items. All right, so for now we can just go right into our object. Items. Here are our object script. All right, and all we need to do here is we're going to come down to, down in here and our unhandled input. And when we add it, this object to our data, we can go ahead and you can do it before you do it, after it doesn't really matter as long as you do it before Q free. And we're going to get parent. So if we look at our main there for a while from our bear or cameras on, we're going to get parent that'll take us up to our main. And our main has access to all of these notes here. So we're then from Maine we're going to get node and the one we want to get as item list or whatever you went ahead and named yours. So good parent dot, get node, open, close parentheses. And inside of our argument here, we're gonna go ahead and get item list. And now what we wanna do with that is we want to add item, add underscore item. And the first argument that we put in here is going to be the text. So we're going to do self.name. And because we want to make sure everything stays nice and looks great, we're going to do capitalize as well, just like we did when we add items to our data. We can do a comma and the next item which you see if this pops up is the icon. So we want the texture here. And for that we can just do self dot texture. So we'll get the texture of the object. So we'll get the texture that we're using for the bear will get the image that we're using for the camera, and that's what we're going to use. All right, so if we go ahead and run this, we should now see it. Add it right into our list down here. We'll see how big it is. And would aside from him a one make it bigger. We want to make it smaller. So I'm going to click on the camera. And that's how big it is. So I can see that I can shrink my bar down and make it a little smaller for the size that I picked here. And if I select my bear, there it is. I kinda like that size. You might want your bigger, you might want a smaller. Again, that's going to be completely up to you. Now if you had this going vertical, I can see two columns being pretty good here on the side. So something that I'm going to do here is I'm actually going to take my Git parent dot getName, item list here. And under the ready. Just for now, I'm going to go ahead and paste the sin multiple times. You might be thinking that's crazy. What are you doing? Well, I'm gonna go ahead and just hit play. And it's just going to add up all these items. And this will help me see the, what kinda spread I've got going on, right? For item so I've got 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. So I can see 10 items only takes me up to here. I've got room for more when I've got the cameras and I went, I only have barriers. I've got 12345678910 and have all this extra space here. With cameras. We've got 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. So we can fit ten cameras across, but we cannot fit 10 bears across. So we need to actually change that. So I'm going to change mine to 14 and that should be good enough to get everything all the way across. So now I can remove, actually I, I'll keep all of that for now. Click on item list and I'll set my match columns 214. And now when I hit play, are bears is not going all the way across. Why is it stopping at 10? Interesting. Puts same column width on. There we go. That looks a lot nicer. So even though we're working with 10 here, I guess it's not going to squeeze any extra zoo. That looks a lot nicer. And I can see what I'm up here. I've still got room, so I'm gonna go ahead and squeeze this down with my game still open. And you can just tap back over to it. I'm just going to go ahead and rerun it. Just going to move this off to the side so that I can see this as I lower this down. I want to go with it. Yeah, I'll go with this size for mine. And I can see my own little preview here. And we've got the little wheel here so we can scroll if we ever need to, depending on how many objects you have in your game at one time. All right, so before we forget, let's go back to our object script and remove all of these. Now we're, we're not automatically adding on these items. And we can run it just to make sure. And you always want to make sure that you're not breaking anything somewhere. Go ahead and add our bear and our camera, and everything's working still. That's awesome. That means we haven't broken anything. Now I do have a little bar here on the side. I don't really like that, so I'm going to make my list here just a tiny bit bigger, just to get rid of that. And there we go. You see now it's gone. Because I don't want to see that unless I have more than one line. Otherwise it's a little weird and it provides false information to your player. With a real. Now when we click on an item, it will also add it to our inventory visually and on the backend into our list of data. All right, so next we'll take a look at, we will take a look at saving our data. That way when we load up the game, we can actually keep the objects that we had, right? Because you don't want to maybe end the game and then load it back up. And then you've lost all your progress, right? Maybe you're doing a longer game rate. Now if you don't save, then it's a little better for shorter games. But it's always nice to have that save option in there. 8. Saving and Loading Data: All right, if one we're going to go over saving and loading our data in to our scene. So the first thing I'm gonna do is I'm going to head up to project. Got a project settings. And under config and our General tab under application, I'm gonna go ahead and turn on use custom user directory. Now what that'll do is inside of the user directory, all OSs have one. If you're not sure where it is, you can try slipping up down the GoTalk directory notes show you the location for your specific OS. For Windows, it is in the AppData. For Mac and Linux. I'm not a 100 percent sure off the top my head. But we're going to turn that on. And with that on, it'll create a folder called hidden objects puzzle game, write the name of our project. If you have the often you have to go through a folder called Good Til and then you have to go into another folder with that and then you can find your project. So I like using custom directory. It looks a little more professional for it to have its own area, the house or your data. So let's go into script and we're going to be going into our global script. And we're going to need two functions. We're going to need 14 saved data. And we go and one to load our data. Oops, there we go. So we're start with save data. To do this, we're going to create, we need a new variable. We're just gonna call it f. And this is going to be for File New. Now that's file with a capital F with an open close parentheses at the end of new. And we're going to do F dot open because we want to open a file, right? We need to open something in order to read to it or write to it. We wanted to directory. And we're gonna do user colon slash, slash, right? And we're going to just call our info data dot DAT. Alright? And then we'll do a comma and we need another argument here. And as you can see, but she would need to know whether we're just reading from a file or if we're gonna be able to write to it and modify it. Now, we're saving our projects. So obviously we want to write to our file, right? Because we want to write new information to it. So we can do F dot, right, and right is in all caps. On the next slide, we can do the actual savings, which is going to be storing our data to do F dot store line. And then inside of the parentheses here, we're actually undo to underscore and Jason and open, close parentheses and inside these ones are going to put data. I'm just gonna put our data. And then whenever you're finished with a file, whether you're saving it or loading it, reading from it, doesn't matter. Always close it at the end. So f dot close, open, close parentheses. Now for the sake of this, I'm going to also do OS dot shell open. And then OS dot. If I just type user and you sit there, get user data directory. Now if this doesn't work for you, then again, you can go ahead and check online for the documentation to see exactly where it is for you. What this should do is open up your data directory on your OS. And this will just allow us to quickly get to it so we can see. Now what good is calling save if we have nothing to say, right? So let's go ahead and save that and go over to our object script. And when we Q3 are before we cue for me, Let's go ahead and call global dot save data. Now, we can save it whenever we pick up an item or we collect one. So let's go ahead and run this and we'll pick up the bear. And you see, it should open up for you right there. And just go ahead. You can see data dot DAT has been created there. And if we double-click that, you can just open that with Notepad. You'll see our object. We've got collected objects and we have our bear in there. And I, when we add our camera and click on that, we can double-click and open that again. And we'll see we now have our bear and our camera. So we see our information is now being saved and stored on our computer. However, we're not actually loading and checking our scene or anything for these objects. So even if we open a backup now, even though it's NR data, we can still see our camera and our bedroom can keep collecting it over and over. So we need to now write our load section. So let's go into global. And we know this works. So we don't need to open that up anymore. It's up to you if you want to leave that there, but it'll get a little annoying over and over. So we're going to start off the same. We need a file, some of our f equals File, New. We're going to open same Directory, User colon slash slash data dot DAT. Oh, before we do that, so I'm actually just going to hit Tab on that to tap it in. And above that, we're actually going to check to see if the file already exists. Now we if it does, then we'll load our data. So what do if app.py file exists? And then we'll pass in a string. So our path which just use your colon slash slash data dot DAT, and a colon on the end of that because it is an if statement. So we'll say if a file exists, f dot open our data. And then we need to read from it because we want to load the information so we want to see what's in it. We don't want to write to it. We just want to take a look at it. And then we'll set data. So our argument at the top are variable. And we said that equal to parse and Jason. And what do F dot get as text? And then, like I said before, whenever we're done with it, you always close your file. All right, let's now and are ready function we can call a load data. And after we load it, we can go ahead and print data. And if you want to check that, make sure it is loading and everything, we want to have a comparison. You go ahead and print before and after it loads. So now if we hit Play and take a look down at our output console, we see collected objects is empty and now it is bare and camera. So our data is being loaded into our variable, which is beautiful. It's great, that's exactly what we want. Now the problem is, is we still have our objects in our scene when our data does get loaded. So we need to fix that, right? We need to change that. So in the next video, we'll go over removing our objects from our scene. And maybe we will take a look at adding it into our item bar as well. Once our data has been loaded. 9. Loading Data to Inventory: All right everyone, we're going to start off with loading, being able to load up our objects that way. Because you see when we hit Play, once we have collected them, will actually keep them here rather than hitting play. And we can just constantly keep opening over and over. And I see they just constantly add to our list. So what I'm gonna do is before we start here, is I'm actually going to open this up so I can delete my data again, because I've got way too many things in there. So OS dot get user data directory, and I'll just hit Play so I can quickly get that up and delete. All right. And I'll remove that. All right, Now we're ready to go. So you do want to come over to your global script because we can't actually get r when data is inside of our routes folder here. Once we export the game, we can't actually use in these images anymore. We're just not allowed to access them. So what we're gonna do is we're going to take the objects that we have and we're going to save them externally so that we can access them later. So I'm going to create a new variable. I'm going to call these GameObjects. And this is just gonna be a list. So when array, so I'm going to go ahead and list in there. I'm going to add camera. And then while I'm here, I'm also going to go ahead and add that we only have to do this for our collectible objects, right? So like our cursor's, we don't need to do that. Our layers, we don't need to do that. Our key. We should do that and just, just in case our player were to say stop before using our key. So let's go ahead and add the basement key in their locks. We don't need to because that'll be shown during gameplay. So we shouldn't need that. And that for now that looks like everything that we need. So let's go ahead and create a new function down here. And I'm going to call this copy objects. And what we're gonna do is we need to get a directory. Now if you've gone through the File Explorer or Finder on Mac, I think it's like that you'll be going through files. And each of these files are called a directory. So we need to create a new one. So var equals directory dot nu. And now we're going to see if it's okay to open. So if we don't have any errors, right? So after dot open and the directory want to open a cyst, our user directory. And if that is books, and we don't want the inside, they want the outside of the parentheses. So I'm just gonna check if it's okay. So if there's no errors accessing this folder, then what we're gonna do is we're going to do dir dot make there. So we're going to create a new directory. So I'm going to create a folder. That way everything doesn't get all jumbled up and we can keep things clean. And we're just gonna type in user or user directory here. And then we're going to add in objects. So whatever you want the name of your folder to be, I'm going to call my objects. I now want to do for OBJ in our variable up top GameObjects. So for, for every item that's in our list, Let's do this. Now. Where I say for OBJ and GameObjects, that OBJ can be anything you want for I 44 stuff where things, whatever you want to put in there. It's just a place holder word that doesn't actually mean anything. It's just a stand-in for whatever item we have that is currently being cycled through. So anything that we do to that OBJ that we're using there is going to correlate to each object in our list. So for OBJ and we're going to do, do a copy, so dor dot copy. And the way copy works is you pick a starting location and the end point that you want to save it. So for in here we do raise colon slash slash because it's in our reds, right? And then for us it is inside textures, Textures folder. And then we can actually just do percent S dot PNG. Now percent S is actually a placeholder. And what that is a place holder for is whatever we declare on the outside, so we just do percent and then whatever we put after that is what's going to fill into that percent S. So we do percent dot OBJ. And now whatever object is, because it's going to take that place. So if we look at the top, we got bear camera basement key. So we're going to replace that number. So we're going to have textures slash bear dot PNG, textures slash camera dot PNG textures slash basement qi dot PNG, right? So we're going to constantly do that. So we're going to look through our list and copy all of those one by one. We'll go comma. Now this is where we want to copy it to. What's going to be our user directory. And then we're going to stick inside of the folder. We just created our objects folder. And then we'll do another slash. And again percent S dot PNG. And just like before, we're going to fill that in with our OBJ or object. Now if we were to run this and open it. So up in the ready, before we even load our data, we're going to go ahead and do copy objects. And I'm just gonna go ahead and do open up my directory. Once it's done loading, so we'll hit Play. And now you should see an object's folder that has been created. And if you go inside of that, you'll see all of your objects from that list. And that's great. So now that they're outside of our game and they're in somewhere safe like or use a directory, we can actually access this. And now we can use this, these images to apply to the objects we want to add into our inventory when we load. And then when we have that, we can then use are collected objects. Data up here that we load in to start scanning through our scene to remove objects. And, and we have really just have a full save and load State working in this. Now if you don't want your data here to save every time you pick up an object, then you can just remove the line here. But just remember to create a save button or whatever, that way your game does. Save at some point. For me, I'm just gonna leave it like this that saves after every time we pick an item out. Now we, we never lose progress as the player. All right, so now that we have that, we can actually focus on loading up our object into our item list, right? So let's head on over to our main scene here. And we're actually going to create a script onto our main. So we're going to add a new script and mature goes into the scripts folder. And I'm going to go ahead and just leave mine as a main for the name. Alright, so we're going to need some variables here. Let's see which ones are we going to need? We're going to need see, you've got a main one here. We don't need anything there. Yes. All right, so we're going to need for create one called I will set that equal to 0 by default. And do we need texts yes. To also create a variable called text. And this is going to be a place holder for textures. Alright, so the first thing we're going to need, and we can get rid of the process function here. We're actually going to create a function that'll create the textures from those objects, or sorry, from those images that we've copied over to our new directory. So let's go ahead would do func create texture. And we'll pass in an object name. So what this, this'll take the name of our object that we passed in and then we'll get the image for it and then create a texture from it that we can then use for inventory for loading that up. So starting out will create a var for IMG. This will be our image. And this will be equal to image dot nu for a new image and do IMG dot load. And this will take a path, a string. So this and we'll pass in our user. And then our objects folder that we created. And then percent S dot PNG. And of course, we'll pass in that OBJ into our placeholder. We can then go to Text to get our texture. And we'll set that equal to an image texture. And we do text dot create texture. Or I'm sorry. We don't want create, we want create from image. And we'll just pass in our IMG the image that we have loaded up. So with that we'll take this. So again, we'll go through, and for example, if we're looking for the bear, and if we pass the bear object in to our create texture function here, we will load up the bear image and then convert that image into a texture that we can use. Alright, so aside from creating a texture, we will now obviously need to be able to assign it, right? So let's add our collected to our list. So funk, add collected to list. You always want to have your function named appropriately. That way you can just look at the name and know what it does. All right, so let's get on with that. So we'll say while I is less than, so remember I at the top, so it's currently 0, less than global doubt data. And we're going to do for our collected objects. Here we go. And we'll get the size of that. So that's rates you don't tell us like how many items are in that. So if you have one item and I is 0, we'll load our first item, right? Because it's less than that. So if that's the case, then we're going to call create texture. And we're going to pass in global data, right? Are collected object, collected objects. And then we do another pair of square brackets and we pass in i. So we're going to pass in that number for that index. And if we take a look, So collected objects I being 0 is going to give us the first object. And then one will give us the second, two for the third, three for the fourth, and so on and so on until we go all the way through all of our objects, right? And then we can do to get node. And the node we want to get, of course he's our item list, right? And we'll do dot add item. And we'll pass in global. Data are objects collected will pass an eye, and of course we will capitalize that. And then for the image which is passed in texts, which is already holding our new image. Thanks to our previous function that we used to create the texture. And to avoid a loop, we can do I plus equals 1. Okay, so while doing this, there is a second way that we can do this. So I can show you that this is one way to do it using a while loop. Now if we were to open that up and take a look, you see our objects, load up our camera and our bare, perfectly fine. So that is one way that you can achieve this. Now, I'm going to show you another way that you can do this. And it's going to be kind of up to you which way you want to do it as well as show you two alternative methods to do the same thing. So for this, we can take a look and take a look at doing a for loop. So for i inside of our GameObjects. So if you remember, inside of our global script, we use a for loop. For I. In, there we go. This will loop through all of our objects this way rather than using a variable for I with a number, right? Because we are associating a number with that. So for this, we can just call it 4, 4, 0, just to keep this a little different, a little less confusing. So say for o or OBJ like we did in our objects in the global. So this will be a little more familiar. So we'll say for object in here, what do we wanna do? We want to create an object, create a texture. Only we don't need this long string. We just need to pass in the OBJ. And then same with our get node on the following line. We can remove this and just put OBJ capitalised and again pass in our texture. So if I were to comment this out, so I'll just highlight all that and hit Control K. That'll make that code not run. So we're now running our for-loop. And if I were to hit Play, you see it loads up and we have both items here with their pictures and everything. So that's just two ways that you can do the same operation here. So I just thought wanted to take advantage of this section here to kind of show you two different ways to achieve the same thing in programming and coding. Here, it's all about problem-solving and finding a way to solve your problem right? Now, our problem was when it was we needed to get a texture of our image in order to add it to our list, item list. And these are two different solutions for that. So I would leave that up to you. Whichever one you want to use is completely up to you. It does not matter here. But with that, we'll stop here, we've got that loading up. And the next one we'll take a look at removing our items from our scenes. 10. Remove Objects From Scene: All right, everyone in this video, we're going to go ahead and take a look at removing our objects from our scene. Now what we mean by that is when we play, we can see that we have our objects added to our inventory. But where would you go ahead and collect them? Again? We don't want that to happen. We want if we've collected the item, we want the item to disappear. We don't want to think about how weird would it be if you go to the kitchen and say you pick up a drink, right? Maybe he gets her coffee, you pick up a cup of coffee, go into the living room, may watch live TV in the morning. And you opt back into the kitchen and there's another cup of coffee. It's like duplicated somehow. We don't want that to happen. So we want to be able to remove that coffee so that when you go back in there, it's not there. The only copy that you have is a cut that's you already picked up. So we're going to do that same thing, but with our bare and our camera here. So we're going to do this inside of our main script here. And we're going to use two functions for this because we don't want our function to get really long. You don't want to have a function get super long. It just looks bad. And I would say it's kinda like bad practice right? At this point. So we'll try to minimize this by using two functions that both do one specific thing. So we're going to create our function. We're going to get remove objects from scene. And that's what this is going to specialize in, removing all of our objects. So we're gonna do if global, if I can spell dot data. I did it again. Collectible or sorry, collected clicked objects. So by saying if collected objects, we're basically saying if we have items in here, because if there's no items in this list, it will, it will return false. And if it's false, then our code is not going to run. So if we do have items, we have at least one item in our list. Then we're going to do for item in. And I'm just going to copy this because we've already written this so many times now. So for every item in our list, so if we have items in our list, we're going to do this to every item. And we're going to start by checking if there's a space in our item. Because remember if we have our basement key, for example, we have a space and our item name, item name. It would be weird to have it as base monkey all smushed together without a space. So we're going to check if the object has a space, right? If space in item. Then what we're gonna do is when DO item equals item dot replace, not replaced by, but just replace. And what that's gonna do this spatially going to replace the first argument that we pass in. The second. So we're gonna do our parentheses, or sorry not parentheses are a pair of quotes with a space in-between. So we're going to replace all spaces with, we're just gonna do a double quotes with nothing in the middle. So I'm going to take them or space and replace it with nothing. So what this ratio do is delete any space in our item name. Now, after we've done that, we can go to the next line and we can delete once so we can back out. So when the same level as our if statement, and we're just going to call remove item from seem. Now we're going to get a bit of an error here because we haven't created this yet, but we're about to, and we're going to just pass in item into our object or pass this into our argument. And now for our new scene, or sorry, a new function, we can create that font can remove item from seeing. Now it'll take an argument, one argument there. And it was a colon and pass. And you'll see all our errors would disappear now. So what do we want to do with that item? We want to take a look at all the children that are everything that's the children of our main scene here. And we want to remove any of them that we've already collected, right? So if we've collected the bear, we want to remove the bear. If we collected the camera, we want to remove the camera. So what we're gonna do, first, we need to get a list of all of our children and our tree. So we're going to see and check, get a list of all of our notes here. Several revenue for child in self.age, children. So for all of our items here, all of our items, what we're gonna do is we're going to check if item is equal to child dot name. So we're going to check if the item that we passed in, which is going to be any of our objects here without a space, any object that we've collected. If our object is anywhere in this list. Do this. And what we're gonna do is we're just going to simply do get node. And we do one dot. Whoops. Sorry if we have to put that between quotes, we do one dot, which means self, and do a slash. And what we're going to put in there is we're actually just going to have our second quote there, right? And we're gonna do space plus item. And that's going to basically get the object that matches our item. And then we can call Q free. So basically we're going to delete any item that matches. Now I believe we could do this, can we not over this, not allow us? All right, so we should be able to use our placeholder just like that. And now when we load up, we can go ahead and, and are ready function. We can call remove objects from scene. And if we hit Play, there, we all are bare and our camera is gone because we haven't collected. And again, I should just have a button setup for this get user data directory. So just to show you it works. I'm going to go ahead and delete my data. So if we start a brand new game, looks like this. We have our camera and our bear both here. I'm going to click buy Bear. Close it. Stop playing, and then maybe I'll come back and I play my game again later write. Our bear is gone, but our cameras, so here because we have not collected that yet. And our bear has loaded rep right down here in our inventory. And now we can click our camera. And if we stop playing, maybe come back again later. Our bear is gone and our camera's gone. So now we've got items being removed from our scene. We've collected them, which is great. We're adding our items to a list of data that we can now save and load. And we've copied objects from our game over into, over to the computer so that we can actually access them to create our textures from it. All right, that'll do it with this video. And the next one. I don't know What should we do? Maybe we would take a look at a draggable objects. We would take a look at that in the next one. 11. Draggable Objects: All right, everyone, in this video we're going to go over creating or how to create a draggable object. So we're going to be able to put up on our screen and then drag it. And for our example, we're going to use an envelope because maybe, maybe you want to create a map where maybe you have a desk, right? And you got to uncover the key by moving envelope, right? And then we can use that key later for unlocking something are used on object for a puzzle or something, right? So let's go ahead and create our draggable object. And we're going to start out just, just as we normally do. So we're going to have a sprite With an area and a collision. I'm going to name my scrape envelope. I'm going to move my sprite or my image in. So I'm going to bring my envelope in. We have our image and now we can set our collision shape, which again, we're just gonna use a rectangle, a fit it as best as you can. Here we go, That looks good. Awesome. And we can save this an envelope, put it in our scene. Excellent. All right, so our drywall object is going to need a script. Go ahead and put that in the script folder. And I'm going to call it draggable. So this will be our draggable objects are ready. So a few things we're going to need here. For our draggable object, we're going to need a mouse enter variables, so we need to know whether our mouse in there, It's in the area we're going to need. Following, which by default will be false. We'll take a start position this right, we can only drag it so far. And if you want to make sure that you can't assign a different type of value to a variable, which can do is you just do a colon and then you can assign a class to it like this. And then we can own our Starbucks and will only ever be a factor too. If you try to assign anything else to it, it will cause an error. So for example, if following, if we wanted to here, we can go like this and call it a bool. And then we would set equal to whatever the value is. And it's not something that you have to do, but it's something that you can do and it's completely up to you. Another thing that we can do, which are actually gonna take advantage here is export. And this will allow us to change it over on the right side inside of our inspector, which really helps with making scripts and reusable. And this may drag distance. And we'll just make this an int, which will be an integer, a whole number. So if we say that if you click on your envelope now you'll notice on the right side, you'll see a section here for our drag distance. So in our ready function, the first thing we're gonna do is we're going to set our start position is going to be equal to self.age position. So obviously our starting position is going to be wherever we spawned this envelope in it. We're going to connect two signals, which we can take them directly from our objects. For doing the exact same thing, we're going to connect our mouse entered and mouse exit. So to save time, we'll just copy both goes over. And since we're dealing with the exact same function names, we can also bring those over as well. And we don't need to change these functions at all because we're going to set these true and false when our mouse is inside and outside. And of course cheese or cursor to let our player know. So that that portion of our objects will remain here. What we do need to add is actually two other sections from I just come down here. And we're going to do an unhandled input, which is good for when you're creating a game here. That way you're not running a check every single second. And especially since we don't need the process function, right? We don't need time to dictate anything in this game. So we can come in and we can do a check if input is mouse button press and we can just put in mouse button one, which will be a left-click. If you want to use, is action pressed. Then you can go ahead and use that to, and you can put in our action name, which was left-click. So if you wanted, you could do that, which would just be just ticks sitting there. So if you wanted to do that instead, you can either one of those or work for this situation and won't affect anything. But we're going to get a check. If if we're pressing our left-click mouse, enter this equal to true, then we're going to set following to true. And for the most part we can just copy this down. Set following to false. And actually what we're going to change here is we're actually going to put an exclamation point right before we put in our input. And what that means is that means not. So we're looking for something that's not true. So if not mouse button pressed long rate. So if we're not pressing left-click and Mao center is true, then following is false. So it's only going to be true when we're clicking. Alright? And we need one more function here, which will be a process function. And this is something that's going to run every frame on our game. So something that's constantly running at all times. And what we're gonna do is we're going to check if following. Equal true, which is only true when we're, our mouse is over an object and we're clicking and holding our mouse button down. And then we're going to do and check if self.position helps if we spell that right. So self.position, and then we're going to check the distance, distance 2. And that's going to take a vector to a variable. So what we're going to pass in here is our start position. We want to get the number distance between where we are and where we start, where envelope is on the screen and where it started, it's gone point. And we're gonna say if that is greater than or equal to our drag distance, then we'll just turn following to false. So this is going to allow us to, when we're dragging our envelope, we're only going to be able to move our envelope a certain distance away from where I respond. That way you can't just pick it up and go drag it anywhere on the screen. You can only move it a set amount of distance. And now we'll just put an else check your your indentation here. We don't want to get lawsuit or constantly weird things happen. So if we're not pass our drag distance, then of course we want to drag our object, which took me self.age, set position. And then what are we going to set it to you? We're going to set it to our mouse position, so get global mouse position. So if we go through this, if we have our mouse on top of the object, mouse entered is true. And if we click and hold our left mouse button, either through using mouse button press with one as argument or using is action pressed. And passing in our left-click input. We'll turn it true. Otherwise it would be more turn following true. Otherwise it's false. I'd have following is true. Then we're going to constantly update its position so that it's always going with our mouse. Just as we are dragging it around. And if we pass distance, the maximum distance that we set for our drag distance following becomes false and we can no longer pick it up. All right, so let's take a look at that. Let's go on into our scene. So back on 2D, click on our main and instance in our envelope. And let's just put it right on the table here. And then we have a selected wouldn't go over to the right and center and drag distance, I'm going to set mine to 100. And we can hit play. And you see our mouse cursor changes. And when we click it, we can drag it around. And as you see it non-stop because I hit that 100 limit. And if we change that to something like 300 would be able to go, will be able to drag it three times and that distance. So it's up to you how far you want to make your distance go. And since we have it off on the side, you can change it on a per object basis. But once we hit that limit and we can no longer drag it and it's no longer going to be following our mouse. Now, I'm going to turn mine back to a 100. And they're real. We now have a draggable object for our game. So there is one thing that we need to adjust because we are going to have a slight bug. If you were not just put that back in new order, it should be. So if we create another object here, Let's see other node in our sprite, our area, our collision shape. We're going to call this our basement p. Remember not to put any spaces in there. We don't want to have an issue. And we can just bring our key into our texture. Center collision shape. And we know save our scene Basement Key. And where's our script here? We'll bring our object script in. So in our main scene, if we go ahead and bring in a key, where's our key? What happened there? There we go. So if we bring in our key and we put it behind our envelope because we'd want the envelope to be hiding it right? Key is probably a little too big. So I'm just going to go back into it and resize it. Resize my scale. Pay by half. So you'll notice something. Now when we're in here and we click on our envelope, our qi actually gets collected. So this is a bit of a problem. Because obviously we don't want that to happen when we want our player to just removing the envelope. So we need to factor that in as well. So inside of our object script, here we go, we can create another variable that is called clickable, and we'll set that to false by default. And Russia and come into our process function here. And we're going to do a check. So we're going to say if not area 2D dot get overlapping areas. So this is basically going to check if we don't have two objects that are overlapping. So if we don't have one object on top of another, then we'll set clickable true. So we're going to set it false by default. And if objects are not overlapping, it to be true, otherwise, we'll be back at our default here false. And now all we have to do is just come down to our unhandled input where we're checking for left-click and male-centered and we're just go ahead and add in as well. And clickable equals true, right? That's all we have to do. Now we can actually come in and move our envelope. And we would have our key there ready to be obtained. So if we just go ahead and check that, I believe I have that in here. And we'll just open up my directory real quick, delete my data. Set. The silver will be able to see it. I can drag this and it doesn't affect our key. Again, I'll do it right in the middle. I can click my envelope and move it around without touching my key. And now they're not overlapping. I can click the key. Alright, so now to do it for this video, you now know how to create a draggable object. And you know how to prevent a, a glitch from happening where you can pick up an object that's behind it. So whenever you want to create a indirect object, you can now just use this script and adjust the distance wherever you need it. 12. User Information: All right, everyone. So I figured we'd take a little more of a chill day here, not do too much. And this video. But what we're gonna do, and if you go ahead and load up rhetoric, we're going to have it so that when we select an object, we actually can only select our key. The reason why we're gonna do this is so that when someone is playing our game, we're not going to have confusion, right? Because if we can select an object, the player might assume, oh, I can use this object for something. And we don't want to give them that false, I guess that false intention, that full false thought process. So we're only going to allow them to select our keys, because obviously keys are to open something, the camera or bear whatever. We just want them to be able to have that right. Collected as we go along. So to do this right, you and do this inside of our main script here. And we're just going to need to connect our setup here. We've got removing objects for place. I don't think we have a thing for this. Yeah. Creating our own textures. No, we do not have one for connecting our signals. Okay, so let's go ahead and we can create a function. And we'll just call it connects signals plain and simple to the point and tells us in the future exactly what's going on here. So we're going to take our item list, which our inventory remember. And we're going to connect. We're going to connect item selected. There it is. Self so to this script. And we're just, we'll call this function on item selected. Ross going to connect from our item list. Nothing selected. I will say on nothing selected Bar Method. And to be safe, will always create our functions before we forget. And same with our next one. Alright. So on nothing selected. What that means is when we click on an empty space out here that it doesn't have anything. Say, see at the moment nothing happens. Our bare still stay selected sort of our camera and our basement key. So what we want to happen is to have nothing selected. So the easiest way to do that is to simply go to our, our item list and just call on Select All. And of course we'll set our item selected. We actually don't have a variable for that yet. So far, item selected. Just leave that as an open string or as an empty string rather. And we'll set item selected to being just an empty string, just like it is in our variable at the stuff at the top. All right, so when we select an item, we're actually going to set our item selected to being that item. Also. Before it, forget the function on item selected for this signal, we actually have an argument that goes in, that's just our index. So I'll just put idx and there you can call it whatever you want. So items selected equals item, list dot get selected items. So since we can only have one item selected, it's only going to get the one item. Oh, my mistake. They're not we don't want to get our selected item. We want to get the item as text. That's what we want to do. So we get the itemize text and pass in the index so it knows. And if you would like you to go ahead and print item selected here if you want to make sure. But we're going to do if not key, to remember, key is going to be in between a pair of quotes and not. You can either type the word naught or you can just pull it the exclamation point. So if not key item selected. So if the word key is not part of our item, then we're just unselect, unselect all. And now you'll see that if we have our bare selected, for example, and click on the outside, nothing is happening now why is that? To our functions are not being cut out. That's right, My mistake. I've gotta go to the ready function. We're not actually connecting our signals. So we'll call our function connects signals. There we go. That's why it's not working. Always make sure that your things are actually running. The now you'll see here when we try to click on an item, if key is not in the name. So we're going to get the name in this case will get bear when we click on it. And key is not in the item name, which key is not in there, then we're going to de-select right away. So it looks like it's not being selected at all. Same with our camera view. If we select our key, key is in the name. So we're not going to, we're not going to unselect. All right? So we click it and I would select it. And if we click in the empty area here, our on nothing selected function, well trigger and we can unselect are key. There we go. So now we can, now we've got a little bit of extra nice desk added for our user here. That way, they know that if they can select something, they probably have to use that somewhere at some point. All right. That's it. That's all I wanted to show you guys for this video. And the next one. No, sure what we're going to cover. Not sure what we're going to start off with. 13. Map: All right, everyone in this video, we're going to go ahead and create our map. We're only going to have our two locations, but it will show you how you can create a map that you can then use to switch between different locations or different rooms. If maybe your game takes place in just inside one building, you'd have different areas setup for different rooms. Or in this case, we're going to be going from this picnic over to explicit in this street here. So let's go ahead and delete that over here. And we go already. So for this, we're gonna go ahead and create a new scene. We're going to use an other node. And for this, we're going to use a canvas layer as this saucy going to help us stay on top. This is going to help us stay on top of everything that's going on. And we'll go ahead and bring in our map, BG, so to speak, our map background. And I'm going to go ahead and save that. We're going to call this map and of course for the center scenes. All right, so just to give you an example, if we were to bring in our map here, you can see our map is on top of everything, which is great. But if we move it up in our tree list, it's still going to be on top of everything. So this is the benefit of using a canvas layer and why you would use a canvas layer for some like UI. So if you had a game with health, you will put your health in the canvas layer. So all of your UI would be in there. If you credit a pause menu, you'd probably spawned that in or instance that into a canvas layer. We'll put that inside of a canvas layer to bring in later. But that's sued. Give you an idea of why we use canvas layer or why we're going to use a canvas layer for this. That way in case anything ever happens for some reason and things get out of order. We're always be able to see our map when we bring it in. So we'll go ahead and just delete that for now. Go back to our map scene. And we're going to need our picnic and our street. Now you see I've named them map and all I did was just add a transparency and an, Wow, I see just in a circle, radius. Now, I can always come in and I can change this, make it smaller or bigger depending on what we're doing with our maps for this. And it's going to go ahead and run this and try and make this not the same size, little bigger. So I'll just written out a little more. Alright, so we can do something like this, right? Maybe we go from there and then we're coming down here. Now, obviously, if you have a map like this, you probably may have a little more details into the actual map itself or make these look a little differently. Have more upper, obviously more than just two locations on here. But we're going to use thesis for an example. And with each of these, we're gonna go ahead and add in an area in a collision as a child and a collision shape. And of course we're going to make that a circle. And we'll just make that cover up our areas like so. So again, with our map, we've got area to D and then our collision layer or collision shape. What would be a circle? Bring it out, line it up, make sure it's nice. Bits covers everything you need. All right, so now we have our two areas that were able to click on. Now, an issue here is we need to be able to detect a mouseclick, which is not something we can really detect easily, I would say just with a click of a mouse. So actually I have to do a tiny bit of scripting for this. So that's easy, that's fine. We can actually add just a script onto our canvas layer. And obviously we want to put this in the right selection assistants and our scripts folder. And we'll call this map angry already. Alright, so with our area setup, we're going to go ahead and connect to signals from VSM. So one for our picnic or two for a picnic to forestry and I have to for whatever other rooms you want to have connected onto this. So we'll go ahead and hook up a male-centered. And I'm gonna go ahead and select or set this. Since this one's for my street, I would do on street, area entered. And we'll do the same thing with an exit. So what do on street area exited? And we do a similar thing on our picnic oops. Picnic area entered. And on picnic area exited. All right, so we have our four function set up here. And we're going to do a very similar thing because we're going to set up a variable at the top of our script for mouse enter, which will be false by default. And in our exited, we're going to set this to false just like so. And on the entered, we're going to change this to true already. So now we have our choose and set ban false set. So we're going to go ahead and create another variable. And we'll call this destination. Let's go to that. And by default it'll be an empty string. Now when we enter the area for our street, we're going to set destination equals. Or street, right? And then when it exits, we'll just set it back to being empty. And we could do the same thing where picnic. Here we go. So set this to picnic. Awesome. It's ready function, we're not going to need it. And we can do an unhandled input. And what do you if mouse enter this true? And input dot is action just pressed or left-click. So again, just like with our objects, if our mouse is inside the area and we left-click it. We're gonna do this. And what is this going to be? This is going to be changing our scene. So we're going to do yet tree dot change scene. And for these overseas or in one location. But what we're gonna do, so we're going to go like this. We're gonna do RES. So our arrays here, colon slash slash. And we're gonna put our scenes folder slash. And then we're gonna put percent S books that did not work per cent with a little S dot T SCN. And then outside of our parentheses, we're gonna do per cent side and pass in our destination. Now this requires us to actually change the name of our scene because right now we got our scene as just being called main. We actually need to change that. So seen, right-click on our main scene and where's renamed the Rio. And we'll rename this to picnic. There we go. And since we did that, we don't need to change anything else. Everything's been updated beautiful. Now when we click on our street, this should then change our scene to street because our destination is going to be street. So when we make this scene, we need to make sure it is named street and double-check your spelling because you want to make sure you're spelling is correct and your capitalization is going to be correct. So let's go ahead and at least quickly make our scene here. So we'll just call the street. You can save this inside of our scenes as street. That's fine. And let's bring in our image and we go zoom out. Now you can position this and resize this to however you would like for your game. I'm just going to leave my default size and just leave it like this. Play my current scene, just get an idea of how it looks. Yeah, I think that's fine for this. You might like to put us a little smaller as fine. It's all come down to your personal preference in this case. All right, so we have our map and let's just run this current scene just to see our make sure things work. So let's click on our picnic and we've loaded up our picnic. All right? And if we open that again, if we click on our street, we should take us to our street. All right, so the map is working beautifully. I would say. And now we can go ahead and for street, obviously we need to put in our inventory and move that kinda stuff all over as well. But that'll be, it should be easy enough as we have our scripts pretty much set up to just move over into each level for each area. 14. Using The Map: All right, everyone. In this video we're going to go ahead and create or use this and take the chance to set up our street senior. So we're gonna get our inventory in here. And then we're gonna go ahead and set up our map so that we can have a button mapped to it so we can bring it up and be able to actually switch between our scenes. The easiest thing to do is to get our inventory will be here. Because now that we're in Gato 3.3 or later you can actually come over top picnic scene, right-click or item list, copy it, go back to our street and paste it in. And now we have that n. If we go ahead and play that scene, we should see our inventory now that loaded up in here too. So whoever for now I'll see the OTP can click is our key still. Alright, so let's get our map going. Let's go over to our project settings input map, and go ahead and set a key for the map action. If you don't have one, of course come up to the top creature action for map, assign it a key. I'm just going to use m for map. It's easiest to remember and it's fairly common. We're going to head over to our global script and we're actually going to load in our map that, well, we only load it in one time in our game, but we don't have to load it multiple times. So var, we'll call this map equals and we'll just preloaded in bringing our map seen. There we go. Just like so. Then we can head on over to our main script, create a variable for map display. So that to false by default. And we're going to come on down and create what we want to create it. Now, I'll go ahead and create my down here at the bottom, we'll create an unhandled input. So now we can check if input dot is action. Just pressed our Math button. So for me, for m, So whenever I press M on my keyboard, we're going to do this. And erasing need to check if map display equals is equal to false. So if we're not showing our map and we're going to set map display to true. And we're going to instance in our maps. So we'll do var int map. And that'll be equal to global map because we want to access that map that were freeloading dot instance. And then of course, once it's been instance, we need to actually add it as a child. So we need to actually put it into our scene in map. All right, Now what if our map is already showing, right? We need to be able to remove it. If we play our scene now. We can bring it up, but we can't get rid of it. Which means once it's up, we have to travel somewhere. And that might not always be the case. Maybe hit the button by accident or you just want to take a look at the places that you have. So let's go ahead and do an else statement here. So obviously we only have true or false for our map display. So if our map display is false, we'll do that. Otherwise, it must be true. So we're going to come down here. We're dealt with set map display equal to false. And we're gonna go ahead and we're going to get all the children in our scene. And we're going to take a look through it. And if we see our map in there, then we're going to get rid of it just like we're doing with our objects when we get rid of them. All right, so just like we do up here for remove item from scene, we're basically gonna do get our children, right. So we're gonna do for child in self.age. Oops, dot-dot-dot yet children. If child dot name is equal to map. Now, do note that I did change my canvas layer over to being named map. So if you want to use the word map here, make sure that you have that set. Otherwise, it's not going to work. So if that set, then we're just going to remove them, get node. And we could just do child dot name, dot Q free. Right? Now what do we run our game or in our picnic, we can hit our map key pops up. We can travel to our new location. But also we hit our MK, our map comes up, we press it again and it disappears. So I can bring it up and make it disappear at any point. And we can travel to all the locations we like or all the locations that we have set up already. So we don't have that setup and we're easily, easily able to move back and forth. Our inventory stays with us. So I guess next, but we'll tackle is we'll take a look at using, are using our key here. And we'll use that to actually get rid of or unlock our door here. And then of course, if you wanted to use this to get yourself into a new area, even obviously, you go ahead and do that as well. 15. Locks: Oops, let's just move that over and get down to the way. There we go. All right, so in this video we're going to go over and look now how to unlock a door using the keys that we find. So the first place we need to go is to stop off at our global because we now have some new data to put in here. So we're going to have a slot for unlocked doors. There we go. That'll be our curly braces. And inside of that we'll have this way or keep all your doors for hours. We're going to call it basement door. And we're gonna set it to false. This is going to keep track of which doors in our game or unlocked and which ones aren't. Now obviously these don't have to be doors. This could be chest or anything else to want to stick in here. Now you can always have multiple things or she can have unlocked doors here and then maybe down here we'll have unlocked unlocked chest. Right. So you could do that and then do the same kind of thing but having chest if you want to have them all separated. But for this, we're just going to keep unlocked doors. And q here. And I believe that is all we're going to need to do for our data here. Let's see. Yes, we've got everything. So next up we're going head on over to let's head over to our new scene because we need to create a lock now. So we're going to have a 2D scene. I actually create this as a spray, so I'm actually going to close that singing. Create a new one, just hit other node. And I'll just create a sprite. I'm going to call this my lock. And of course, we're going to have an area 2D and a collision shape with it. So for my lock, I'm going to go into my textures. And where's my lock here? There we go, basement lock. I'm going to bring that into my texture. And there I go. Alright, so we have our nice little lock here. We need our collision shape to cover it is a rectangle. It means it doesn't exactly fit. Now you can cover the whole thing or you could just cover the LOC area. It's completely up to you. It's your game. Do what you feel is best. Myself. I think I'm going to open up both of those. Now when we just have to get into the area called the slot, save it in my scenes. Now over my street, I'm going to bring it in and get it all placed. I'm just going to put my lock right on the door here. Let's see how that looks. Player scene. All right, so that gets the idea across that this door is locked. All right. Perfect. Now it'll do. So let's back to our lock scene. We can actually create a script now for a lock. And put this into your scripts folder. And create. Okay, Okay, What have we going to need? We're going to need a few variables here. Let's do our mouse entered, Of course, which will be false by default. And we'd actually borrow that in a moment. We're going to need, we're going to export a variable called needed key. And let's tell them that tell the engine that this has to be a string. We're going to export a another variable for door, which will be a string as well. And another one, once again, be a string, we'll call unlock. Image. Now, might change this out later from I'm like image to something else, but that's what we need there. Add our text already. Now in our ready, we need to connect up our area signals, which we can borrow from objects here. And just paste that right on in there, as well as the two functions for it. Yeah. All right. Now, that's all setup is the easiest part. We don't have to do that constantly, right? We're also going to need a signal for this. So we'll have a signal called unlocked. What do we have this already over here? No, we do not. And I don't think we use one over here either. No, we don't. So we're going to have quite a few new sections here. So let's start by creating. Now we don't need to do that. Let's do it. Start with our unhandled input. On-hand, unhandled input. And we'll check if the input is action just pressed, are left-click and a mouse enter is true. Then what we'll do, slide that out of the way. Then what we'll do is we can go ahead and check. So we'll do if a parent Item Selected, which we do have set up here? Yes. Yes, sir. Item Selected there. Cool. All right. Just making sure. So that's where we had them. We're getting that from our main script. So when we add in our lock, as you see here, we're gonna get our street and we're going to be checking this script, which is our main script to see what items selected is. So if get paradata item selected is equal to the needed key. So if the item we have selected, which can only be our keys, if that matches the key that we need to unlock this door. And global, global, not global. What do we do in their global data? Unlocked doors and just make sure I'm spelling it correctly. We used we used uppercase here. Okay. Always good to know, make sure you get it right. Otherwise you'll run into errors. Unlocked doors, door. So pass in door here, which is the name that will give it, is equal to false. Then we will use a function we're going to create called unlock. Low-pass in the needed key. So to get rid of this error right now is go down. And I just got that backwards. And we'll create our unlock function and pass in one argument. We'll call it C0. For now we're just past just the way. That way we get rid of all of our errors. So what we're doing here is whenever we left-click inside of our Locke, we're going to check if the item that we have selected right here on our main script, if that is equal to the key that we need to unlock this door. And if our door is set to false, which is up here in our global and right here. So if our doors not unlocked, and the item selected is the key that we need, then we're going to unlock it. And how are we going to unlock this? What we're going to use this function called unlocked. Goats give ourselves some space there. It's getting low, too crowded. And how did we do this? Well, we use if global data on a locked doors and door. My mistake where I'm actually checking the we're actually starting around one. So let's go back. I delete the line, get their cut that right away. But if you were to emit our signal, unmarked. And we'll pass in the argument of a key. And then we'll set our global data. Unlocked. Doors. Of course will pass a door. And we'll set that to true. So what we're doing when we unlock it, we're going to call emit a signal up to our main script. And then from there, that is going to perform options to get rid of the key and everything for us. And I have a title, they want data and not direct. Alright? And then we're going to set our door, the door that we're unlocking. We're going to set it to true that way we know that our doors already been unlocked. Then of course we can go ahead and we can save our data, global dot save data. And that's all we have to do inside there to unlock that door. But we do have one more function that we can do. We could share. Yes. So do check unlock door. And this we're going to use this to check if our if our doors already been unlocked. And if so, what do this? And if not, we'll do nothing, right? So if we just grab this global data on lock doors, unlock or unlocked doors, door is equal to true. So if our doors already been unlocked, then what we'll do is we could actually just cue for yourself, right? Because we don't need our lock there to be displayed. We can just get rid of it or doors already open. Already. And now we just have to handle what happens when our signal is emitted and connect our signal to our main script here. So that'll be in our connected signals here. Two and grab our LOC dot connect. And you'll see our signal should pop up here. And if not, then we can just type it out. We just call it unlocked self. And we'd just call this a removed key. Or if our Remove Key not removed remove key. Now we can create this function. Remove key. So when we pass this in, we do need argument. Remember we're passing in key when we admit our signal. Now will we know which key to get rid of? So that's good. Var key index this right, we know which item to remove. And this'll be our item list. Dot get item, or sorry, not get Adam gets selected items. Selected items, which can only be one item that's selected with the way our thing is set up. So this'll give a slow report back a number which tells us what item we have slept well, we have item 0, item one, item two, item three, et cetera. So it's going to give us that number. And then we'll do, go ahead and get rid of that item, list dot remove item. And we'll pass in that key index. And that's actually going to give us an array. So we'll say 0 because it's always going to be the first item because we're only have one item is selected anytime. And we'll do global data. And this we're going to access our collected objects. Dot erase, item selected. There are key is no longer going to be collected. We don't need that in our inventory to be displayed. Whenever we reload up our game again. And then we'll just call R on nothing selected so we can de-select everything That should work. Are ready. Let's see it. Let's go ahead and run this now. Oh, attempt to call connect on null instance. That is because our picnic does not have on. So let's just go to our street and run that scene. And we should be able to use her basement key and click on our lock. However, nothing's going to happen. Now, if you're paying attention as we're going through that, We didn't set up some of our things. We export some variables where we didn't actually select them. So as you see over on the right-hand side now, if you select lock, we can put it in the key that we need, which is our basement key. We can put it in the door that we are basically door. And remember that door has to match what you have typed down here. And the unlock image, right? We don't actually need that anymore with this. But if you have a different image, I'll show you how to do that as well. If you have a different image that you want to display. So if you go ahead and run this, you might come across an error. When we're running it or when trying to unlock your door. About a dictionary, issue, invalid index. Go ahead and just delete your old data. And you can go ahead and just recollect your objects. And you should see it. Just show up as being okay now, when you run it. Now for the picnic, obviously we have a lot here, but we don't need it. So for now, I'm just gonna go ahead and we can run that. And you can pick up your items. We'll grab our key, go to the next map and we'll see you in clinic or key, click our lock and are locked in. My case was already open from testing. So I would have to delete that, which I will do right here. So hit play that opens and delete my data. And we'll just stop that from popping up. We'll go ahead and rerun that. Now I can collect a bear, my camera, move the envelope grim my key, go to the new location, select my key and lock in. There we go. And our doors are unlocked, our key is gone. Now we do have one issue. So if we go back to our park and move the envelope, are key is still there. So we're actually going to need to put in a code to remove our key as well. Now, well, we can't constantly come back and get it and keep grabbing it even though our doors already unlocked. But before we do that, let's come over to our lock here. And let's see, we unlock it. When we do that, we met our signal that comes over to our main to remove key and that's connected. All right, so what we'll do is on our lock, when we call our unlock here, right after we save it were actually go ahead and self.age Q3. And now whenever we unlock it, the door is going to be well, it's going to be already unlocked for us. And make sure to run your check unlock and are ready function. And just so that we can check after once we've already come in, check on lot right door, so we'll pass that in. And now if we were to run this scene since 30 on locked, that is our luck. We want the street. What check here and it's completely gone because it's already been unlocked. And now if you go back collector key and come back, we should be able to unlock it and the key or the lock will disappear for us. All right, so in the next video we'll take a look at removing the key so that we can't constantly pick it up from our picnic scene. And we'll take a look at not needing to have locked here in our picnic scene that we see is that don't have locks, won't have errors in them. 16. Fixing Lock Signal: All right everyone, We're gonna take a look at removing our keys from our scene. Let's see, we got remove key here we are in our main script. But remove key is for when we unlock a door, what we wanna do is remove keys from scene. Let's see where we were moving our objects right here. So let's go ahead and come in and we'll just sneak it on in here would do remove keys from same. And of course, we don't need an argument in for this one. Because we'd just go ahead and check for door in global data on locked doors. Oh, okay. There we go. So I'm just going to check all of our doors. We stopped the past in there. Why didn't I get rid of that? All right. So we're gonna take a look at all of these doors here and we're going to check to see if there are false or if they're true. So for all of our doors, if our door for door is, is equal to true, then a must already be unlocked. And since our door and keys are listed the same basement door and we get the basement key, right? Right. And what we're gonna do is we're going to create a variable called key. Key will be equal to Door dot replace. He's equal to dor dot replace. And what this allows us to do is actually replace one character with another and the character we want to replace it as a space. And we'll replace that with just an empty string, like that. So, like so, so that's going to remove our string. So instead of having, having it like this, what we're doing is we're taking that space in between. We're taking that space in between. And we're gonna make it like this now. All right? And then on our next line, we're actually going to do a similar thing here. And we're going to replace the word door with the word key. All right. And now we can just remove item, remove the item from our scene, which is key. So we will call remove item from scene and pass in our key. So we're going from basement. Door to basement door. And then we're replacing door. And that circle I'm from basement door to Basement Key. I hope that makes sense and I hope that helps understand what's going on. We're going from basement space store that basement door with no space. And then we're going from basement door with no space to basement key with no space. And then obviously if we take a look at our last year basement key with no space, that's what's going to be removed from our scene. So we just have to call this function up and are ready. Remove keys from scene. And now for luck, well, before doing that, let's go ahead and test us, come into our picnic and remove our envelope. Anarchy is going. Alright, so that's working now to get rid of the connection issue for our lock. All right, so for that we can check if the lock is unseen and if so connected, right? So for child in self.age get children will check if locked in. So we'll say in child.type name, right? Then we won't connect this. So if Locke is in child.value would do that. And so anytime we'll connect that. So if we run this, we have no errors. If we remove this lock from our scene, we should be good now. No, We're good already. And if we go to our street or lock should automatically delete itself. And it does. All right, so for one final test there, I'll go ahead and get my directory, delete my data. And we could test this just like a new playthrough rate. Except for that comment that back out. So I don't open that right will collect a bear. We'll click our camera and the envelope. Click our key. Change over to our alley. Flick our basement key, open this up our lock. All right, that's gone. Change back to our picnic or key is still gone. Come back to our street. The lock is still unlocked and we're not having any connection errors with our signals. Alright, so now we're able to unlock the door we complaint from start to finish. We can move to our map. We're removing any keys for doors that have already been unlocked. We're only connecting our lock signal if we have something that's ready to be unlocked in that scene. And our inventory transferring over. And of course it's completely saving with everything that we're doing. And all of our scripts can be completely added on to anything. So if we go and take a look, we can add our draggable script to anything that we want to grab and move around, like our envelope. So if you want to hide something behind another object, you can do that. We've prevented the user from collecting something like a key behind the envelope. That way, you actually have to move the object before collecting it. The user can only select our keys that way they know that the keys are useful and everything else is not. We have a locking key system setup so you can now unlock chest or doors or anything like that. We have a map setup so we can view the map and put them away as well as use that map to travel between different rooms or in our case, different locations completely. And we have an object script that we can put on any object that we want to use as a collectable for our game. So we have a lot of different features implemented in here, as well as a lot of our scripts being able to just be overused to slap it onto another object, slap it onto another lock. Our main script to slap it onto another scene. All right, we've got a lot going on here, and if you've made it this far, go ahead and give yourself a pat on the back. You've done a lot and I hope you've learned a lot while doing this. 17. Alternative Options: All right. Obviously, I can't leave you guys off. I did say that I was going to let you know if you wanted to use the unlock image. So when you unlocked the door here, if you wanted to display a different image, you might want to do this, maybe with a chest or something. So you have like a closed chest or an unlocked chest or sorry, a lot chest. I don't want you unlucky moment and display different image. Or in this case, maybe just instead of showing a lock, like we haven't here, maybe you have a another image. We're clearly shows that it's been unlocked. Maybe you want to do something like that. You can definitely do that and I'll show you how to do that. Inside of our script, we have the unlock immature. So all you would do is just grab any image that you want. I don't have one on hand here. So I'll just use my basement key for this example. And just right-click Copy path and paste that into your unlock image. And then inside of the script when need to create a new function called create textured. This'll take an argument, just one argument. We'll call LBJ. And we'll say var I equals image, IMG dot load. And what we're going to load in here is you can just pass in the full OBJ if you want, if you copied your entire path over. Next up, we will have texts which you see in the top right. Now variable texts, that's where this is going to come into play. Equals image, texture. New texts from image or IMG. So what we're doing is Michelle taken our image here and we're creating a texture for it. And let's see, where is it unlock. So instead of using Q free, what you would then do is call create texture, and you'll pass in your unlock image. Like so. So if I just come into my main and delete this, this will pop up. I can delete my data. Boom. Turn that off. So now if we were to play through our game, we'll click, boom, boom, grab that. Go to our next room, which we have a lock. Now instead of changing it, we actually did not assign our texture. That was my mistake. So. We created it. Here's our lock, created it and we didn't assign it. And so self.age, texture, texts. So that's what we would do. And I'm going to need to delete my data again for charity did it. That books will do that. There we go. So now that we replay it, collect, collect, move the envelope trimer key scenes. Now when we unlock it, we see our texture change. So obviously I'm just using a key here, but you're just change that to whatever you want your unlock image to be. So you can really use unlock images like that. Or you can just not use it in just Q at free. Either way there, that's completely up to you. I'm skinny if Q free because I don't have it unlock image. And if you wanted, you could even use both of them at the same time. So you do if unlock image equals, right, if it's nothing, it's an empty string. Then we can do our self dot Q free. And if not, then that's where we can pass in our sections here. So if you wanted to use both, That's another way that you can do it that way. I you can only use unlock image on locks that you want. T is the image on right. Now likewise, we could also use create texture there to create your image. Or if you want to use different locks, then do just to explore, write var lock, and just pass, pass that in as a string. And now we click it, you can just bring in your lock, such as spring in the basement lock. I always click and drag it in. But if you want, you can just bring it in like so, just like that. And then on you're ready function. You can create texture from our lock. If I were to get rid of it from here. And do self dot Texture tags. So if you all make it a little more customizable even further on, you can just do something like that and you can just pass it in. Same thing. When we were open this up, it's going to look exactly the same. You shouldn't have any issue. Of course, my data's getting in the way again because we already have the stuff unlocked. Should be the last time we do that though. But you can see now we have visually the exact same icon, the exact same thing here. So that's completely up to you. Which route you want to go, whether you want to use your what do you want to use the unlock image or Q3 or a combination of using both of them. And then again with your log, if you want to use a, an argument in there for your texture. As you see when we pull it in, we can change the texture here when you pull are noted. So it's not completely necessary. But if you want to do it through code, you could do it that way. Again, completely up to you and how you want to go about doing that. Just a little, little more options for you to go through and decide how you want to go about doing that. Personally. I'll just bring that in. I don't have recent Maya not to do it that way. So I can just remove both of those myself, as well as our lock there. All right. So that'll do it for the, for all your options here. If you don't know how to play audio, then I'll do a quick video in the next one is showing you how to play audio that you assigned to it for your unlock and things like that. If you wanted to do that or if you wanted to play some music in the background while you're players just looking around. 18. How To Add Audio: All righty, welcome everyone. And in this video we're going to, I'm going to show you how to play some audio for the game. I do not have any audio on hand for this project. But if you have any, then you'll probably go ahead and have a another folder year. Create one called audio and go ahead and just keep all your files in there. As a 3.3, you can bring an MP3 file if you would like. But are you gonna do, for example, here in our first or in our scene here? If you want audio to play all the time, then we can just go ahead and add an audio stream player. You don't need to D because we're not doing, we don't need anything directional such as something way off screen or anything. So we can just do an audio stream player. You can name it whatever you would like and grab your audio file. I just drag it on over into the stream and make sure to test it and adjust your volume dB here. Sometimes things are a lot louder than you may think it is. And all you wanna do if you want this to play, it's like a background music. You can just set it to autoplay and then it'll start playing as soon as your thing loads up. That's one way that you can go about doing that. And if you want to do this in the form of an unlock sound or something, then we can do that within you could do that within the lock itself, right? You can create an audio shrimp layer and drag in your unlock sound, a gesture so your audio, your volume decibels the DB. And then when we're causing unlock here. So when we unlock right after we save data here, we can come in here and get your audio shrimp layer, whatever you called it, a to say dot, play, this like that. And we don't need to pass anything in for this, and it'll play our unlock sound. So either Scott grab your audio and put it in there into the stream section up here. In this case for our unlock audio. Or over here in our picnic. Again, cone audio, audio shrimp layer. Grab your background music that you want to play for this area and dragged into the stream section. And then just enable auto play. And remember to set your volume decibels to make sure it's not too loud in the player's years. So that's how you would set up the audio usage for that. It's very simple. Again, I don't have any audio for this, but just grab your audio, drag it in, drop it. I hit Go ahead to autoplay. So please excuse of string starts. And then over in the lock, create an audio stream player again. Grab your unlock sound, drop it in, adjust your volume decibels and your lock script. When you call unlock, go ahead and just play the audio. So if you have audio for your game, just went ahead and move that accidentally. But if you have audio for your game, whether it's background music to play constantly or if it's an unlucky zone, that's how you would do it. I'm just going to go ahead and remove this since I don't have any just to remove any potential for any possible problems. Hello. It's not what I wanted to come here, delete that, and save everything. Alright, so there you go. We've got a reusable scripts. You can jump between areas. There's my texture experiment in. All right. So we've got maps, we can jump between areas. You got collectible objects. You can just put that script on any object you want to be collectible. We've got draggable objects again. And the things you want to drag around, you can go ahead and just put your draggable script on it. We've got keys so we can collect. And that's paired with our locks. So we can go through a key and unlock system. We've got our mapped to transfer between different areas. We remove any objects as well as any keys from our scene that have already been collected, and any keys that have already been used to unlock doors. And we're saving and loading up our data. All right, So we've done a lot to this course, and I hope you've learned a lot. But there's your basic core for creating yourselves a hidden object type game.