Hey guys, this is Master Jake again. Today, I’m going to be giving you guys little tips on when you’re making your batch files, because I know I haven’t really specified like – I mean some important things. So I'm going to go ahead and open up a notepad and do the same if you want, alright.
So in most of my videos, I show you something that you might set a—stuff like that and I never really went into detail on how to make it more organized and more error free, like let’s just put this, make sure you watch my other videos so you know how to do basic things. We’re going to just say, you know, set, confirm, equals, input, something. Okay, and then we’ll say Echo, confirm, pause, greater nul and exit.
You’re going to save this, we’ll put it tips.bat and change save as All Files and make sure .bat is on the end, click save. And I’m going to open it up. Okay you’ll notice I’ll type Hello World and it writes it and it closes just like wanted it to. But let’s say I want to screw around and I’m not going to input anything. I’m just going to press enter. I’m just going to say Echo is Off.
Now you never want your user to be able to screw around with your batch file and make you know, like – how do I say this, unrecognized things happening I guess, okay. So let’s just keep going with this, and I’m going to say go to A and we’re going to put an A label here and it clears and save it. Alright, here’s another example of an unorganized and unrefined batch file you could say.
Alright, I'm going to input Hello World, it says Hello World. I’ll press a key and it goes back to that. Now you want them to input something else, I would just press enter now. It’s going to say Hello World again because the variable is still the same thing as I said the last time.
So I'm going to show you a few tricks today to stop them from screwing around your batch file. Okay, I’m going to clear everything, Echo Off. Now, we’re going to have a variable set confirm equals input some texts, okay. Now, right after they input the text, right after you set the variable, you’re going to want to do this checked. If not the defined, confirm. Now basically what this is saying is it’s part of the statement, I know I had a statement and totally I didn’t include this in there because I just wanted to keep the basic things in the statement
Then, basically this is saying—we’ll just take not out for a second. Now what it’s saying is if the variable confirm if defined, I actually inputted something and just didn’t press enter, then it will do something, but we’re going to put if not confirmed or if not defined confirm, and you don’t have to put the percent signs around the variable name when you’re doing this kind of statement. In most cases you would, but you don’t have to.
Also, in my statements, if you’re doing this one line, you can just type it over here but if you’re going to do multiple lines you need to put a left parenthesis and at the end put a right parenthesis and then you make a block of code like Echo, Echo, Echo pause clear Echo, and stuff like that, you can put multiple things to do for one statement.
So we’re going to just have it go back to A, we’ll put an echo dot statement right before that like right inside the variable so it goes down the line. Okay, so if it’s not defined, it’s not going to crash the program or echo nothing—it’s just going—it’s going to go back and ask them to do it again, now they can’t input nothing as you answer, okay that won’t work. Now after you check if it’s defined or not, and you do what you want to do with the variable and say, after this we’re going to have an echo down the line and then it’s going to echo the variable, confirm and then pause, and then go back to A, now this would send a back up there and asked them to input again and they would, but now they can press enter without imputing anything and it will be defined, it would just be the thing to enter the last time.
So to clear the variable and make it nothing again which is what we’re going to do, right before you go back up there, we’re going to put set, confirm, equals, you don’t need a space or anything after that, just set, confirm, equals, no slash P, you don’t want to prompt them, you’re just setting the variable to equal nothing in that way they can’t screw around with it. So, let’s save this and open up tips. So I'm just going to press Enter, Enter, Enter and it’s just keeps asking me.
Okay, I’ll put hello world, my name is jake, okay it’s going to save that and then we press and key and it goes back up to ask you again. Now let’s say I’ll try to press enter, I wanted to say hello world my name is Jake again, it’s going to ask me again because it cleared the variable, it has no recognition of what it was. So that is just something you can do to help you for batch files more clearing things. I’m also going to show you a commenting way that I’d like to use of course if you used a batch files, you know you can comment, I’ll type an REM and then the comment like, ask the user to input text and that would not appear inside the program, that’s just a comment.
But those are really hard to read in the really big ones, so I’d like to put 10 colons a space and then a comment in caps and then ten more of these colons. Now when you’re going through like three hundred to a thousand line program, it’s a lot easier to find comments that you need when they stick out like this and I’ve built a batch file text base rpg recently, it’s probably been about a month I guess and I had tons of these comments in there which helped me out. I never really stay at rpg though. I might make another one and I’m not sure.
So, that’s just a few tips to help you out with your batch files to make them more stable. I hope you enjoyed the video. If you have any tutorial requests or anything like that, just send me an email and visit my site, that would be back up soon. Thanks for watching the video, see you guys later.
Transcription by:
Scribe4you Transcription Services