 Okay, hi everybody. One question I get all the time on my YouTube channel is how do I create a pause function in my game? Today I'm gonna answer that question in just a few short minutes. Another question I get is what IDE do I use? Genie, G-E-A-N-Y, free and open source, check it out. Okay, so let's take a look at the program that I have. So I'm gonna hit function F5 and run. And I just have a very simple program. Assume this was a game of some sort. And I just have a little, in this case, a little turtle triangle going around the circle forever. So here's what we have to do. First thing I'm gonna do is I'm gonna create a variable called isPossed. Okay, I'm gonna set that equal to false. So what this means is that my game is not paused. So in my loop, I'm going to put, if not isPossed, then I wanna do these. So all of my game information would go into here. Okay, now again, depending on what game system you're using, if you're using turtle or if you're using Pygame, this would look a little bit different. But this is the general idea. And another thing I have to do here is else, win.update. If you don't do this, your computer will probably lock up and grind to a halt, which mine just did. So as I was testing this. So I'm gonna run it and just make sure it's still running exactly as I expected it, which is good. This is what we expected. So again, I've created a Boolean variable called isPossed. You might wanna just call it paused, depending on how you'd like to do it. But I always use is, so I know it's a Boolean. So while true, so if the game is not paused, if it's not paused, this is what I wanna do. If it is paused, otherwise else, do this. You have to do this update, otherwise, again, the screen will lock up. You may not need to do this if you're using PyGame or some other system, but with a turtle, you do need to do that. So let's test it. Let's switch this over to true. So if the game is paused, it should just sit there and do nothing, which is exactly the effect that we wanted. So it's not very useful because you have to change the code every time. So let's start it out as false. And then I'm gonna make a new function called define. I'm gonna call it toggle pause. So this is not very good programming practice. Probably you should put this variable into an object of some sort, but I'm just demonstrating the principle. I'm gonna make this a global variable is paused. Otherwise, I won't be able to change it. So if is paused equals true. Now this equals true pot is actually optional, but I'll leave it here to make it clear what I'm doing. So if it's true, I'm gonna change is paused to false. Notice I've got two equal signs here, one equal sign there. Else, so if it's not true, then it must already be false. So I need to set it to true. And then I need a way of toggling that. So I'm gonna do win.listen and this sets up the program. So it listens to the keyboard. And I'm gonna do win.onKeyPressTogglePause. Notice there's no parentheses here. Okay, even though there's parentheses here, we're not putting them here. It's just a quirk of the way this module works. So toggle pause and I'm gonna use the P key. It makes sense, you can use whatever you want. Oops, I've been doing a lot of Java lately. So what this says is when I press the P, call this function and this will say, if it's paused, unpause it. If it's not paused, pause it. So I'm gonna go ahead and run it. Function F5, so Bob is moving. I'm gonna hit P, Bob is paused. I'm gonna hit P again. Bob is not paused. P, P. So not paused, paused, not paused, paused. That is that. I will put a link to this code down below so you can play around with it and come up with your own variations of that. But that's the gist of it. You need to have a variable that controls whether or not the game is paused. It could be game is, game playing. You can call it whatever you want. Whatever makes sense to you. And in this case, it is a Boolean. It's either paused or not paused. So inside this part of the if loop, or if statement, excuse me, inside the while true loop, if it's not paused, then we do our game stuff. If it is paused, just keep updating the screen. Otherwise, your program will grind to a halt and you'll have to force quit it or even maybe restart your computer. So yeah, thanks again. I get that question quite often. And I thought today I had a few minutes. I thought I would answer it. So good luck. Subscribe for updates and keep on coding. Take care.