Now i know how to create what i call tags
for example :startgame
And i know goto :startgame or in some occasions just goto startgame will take you back however
when i am doing if %selector% == r goto :Start_1
it just simply will close the batch file and i have tried with caps and without and without the :.
Now don't just be rude and call me ignorant i know basic batch
This is my start code
:Start_1
echo **************************************************
echo ************App selector by michaelukz************
echo **************************************************
echo **************************************************
echo To select an app press any button.
pause
This is the code i am trying to get to work
:Selected
echo You have selected your file.
echo If you wish to choose another file press R.
echo If you wish to close a program / file press C.
echo If you wish to close press any button.
SET /P"selected=Input letter here: "
if %selector% == r goto :Start_1
if %selector% == R goto :Start_1
if %selector% == c start taskmgr.exe
if %selector% == C start taskmgr.exe
if not timeout /T 3
echo Going to close menu
goto Closemenu
all the rest works except goto start_1.
Please help but don't be ignorrant - i have seen other people on here acting snarky as such.
A few things...
What you are calling tags are usually referred to as labels.
In your code, you are setting a variable called selected in this line SET /P"selected=Input letter here: ", but in your IF statements you are comparing to a variable called selector.
The line if not timeout /T 3 will not work. As #Magoo pointed out in a comment to the question, the syntax of if requires a comparison operator if [not] something compare-op something_else dothis.
take a look at CHOICE command, also you misspelled selector var name in SET /P
#echo off
:Start_1
echo **************************************************
echo ************App selector by michaelukz************
echo **************************************************
echo **************************************************
echo To select an app press any button.
:Selected
echo You have selected your file.
echo If you wish to choose another file press R.
echo If you wish to close a program / file press C.
echo If you wish to close press Q.
choice /C RCQ /N /M "Choose wisely [R,C,Q]" /D Q /T 30
goto action%errorlevel%
:action1
echo option R
goto start_1
goto selected
:action2
echo option C
start taskmgr.exe
goto selected
:action3
echo option Q
goto closemenu
goto Closemenu
Related
code:
echo To Start, type start
echo To view Options, type options
echo To Quit Game, type quit
set /p input= Command?
if %input% == start goto Start
if %input% == options goto Options
if %input% == quit goto Exit
else (
goto Menu
)
Basically what it should do is typing one of those choices will go to that part of the code, and typing something that isn't specified will run that script again. This works as intended, but my problem is when I type "not blah" (without quotes, where blah could be anything) it runs the script despite there not being specified action for blah in the code.
Why?
Besides the fact that you did not double quote your variables when comparing, you cannot use else like that. Else has to be on the same line as the closing parenthesis of the previous if statement and the opening parenthesis of the else code block. i.e: ) else (
Anyway to eliminate the need to accommodate for user errors in typing commands just use choice:
#echo off
:menu
choice /c SOQ /M "[S]tart, [O]ptions, [Q]uit"
goto opt%errorlevel%
:opt1
Echo this is the start section
goto :eof
:opt2
echo this is the Options section
goto :eof
:opt3
echo This is the Quit section
exit
:opt0
Goto menu
I'm in the process of creating a mini-game using batch and one of the useful tool ideas was to have an interactive notepad so that users could store information throughout the game and refer back to it later. So far I have created the option to goto a notepad within an In-game pause menu but wasn't sure if it was possible to save results without outputting to new file on the desktop
:PauseMenu
cls
echo.
echo %Alias%
echo.
echo Notepad
echo Stats
echo Untitled2
echo Untitled3
echo Untitled4
echo Untitled5
echo Untitled6
set/p PauseMenu="N, S"
IF ["%PauseMenu%"]==["N"] goto Notepad
IF ["%PauseMenu%"]==["S"] goto Stats
IF ["%PauseMenu%"]==["N"] goto
IF ["%PauseMenu%"]==["N"] goto
IF ["%PauseMenu%"]==["N"] goto
IF ["%PauseMenu%"]==["N"] goto
IF ["%PauseMenu%"]==["N"] goto
Any help would be appreciated, thanks.
PS is it possible to go back to the previous page from a menu?
Simplicity itself.
First, some renaming may be in order. notepad is a supplied utility and pausemenu is being used both as a variable and as a label. This is not invalid, but can be a little confusing.
Further, if you are choosing between a set of keys, I'd suggest you investigate choice. choice has a number of advantages, like it only accepts one character, no enter is required and it's not necessary to analyse the entry.
So: revising your code:
:p_pausemenu
pause
:PauseMenu
cls
echo.
echo %Alias%
echo.
echo N Notepad
echo S Stats
echo 1 Untitled2
echo Z Untitled3
echo Q Untitled4
echo J Untitled5
echo X Untitled6
:: Note that the processing of ERRORLEVEL must be in reverse order
choice /c ns1zqjx
if errorlevel 7 goto labelx
if errorlevel 6 goto labelj
if errorlevel 5 goto labelq
if errorlevel 4 goto labelz
if errorlevel 3 goto label1
if errorlevel 2 goto stats
if errorlevel 1 goto unotepad
:unotepad
start "Notes for %alias%" notepad "c:\gamedirectory\%alias%.txt"
goto pausemenu
:stats
:: List your stats here
echo Stats for %alias%
goto p_pausemenu
Here, a menu with a number of unimplemented options is presented and the choice command (see choice /? from the prompt for more options) waits for a choice to be made.
errorlevel is set according to the choice made - but since if errorlevel n means if errorlevel is n OR GREATER THAN n you need to process errorlevel in reverse order.
Then each selection is processed. n will start a notepad instance and load the alias.txt file from the game directory, then present the menu again as it returns to pausemenu. s will show the stats (idk what you need for that) and then return to p_pausemenu which will pause and then proceed to show the menu when the user signals to do so.
I looked for quite a while and couldn't find a good solution to my problem. I want a batch program to "look" in a .txt file for the command "" and if that word is in it, then to execute a different command. If the command existed, I would want to do something like set %textfile%=text.txt and if that worked I would then do if %textfile%==update goto update which would be an easy way to start an automatic update if this was in a loop. So basically, is there a command that sets a text file in %text%? This is the code that I am trying to add this into:
#echo off
color 0f
:start
echo Welcome to Master control pannel
ping 127.1 -n 4 >nul
cls
:options
cls
echo What would you like to do first? (Type the number of the operation you want to start)
echo.
ping 127.1 -n 2 >nul
echo 1. Run a command off of all computers
::(I want to run a command by sending a message to a text file but want recieving computor to be able to read it and execute it, how could I read the command and then do what it say, for example, if the command says "echo Hello" I would want recieving computor to say "Hello" )
echo 2. Stops the current command
echo 3. List all computers
echo 4. Open remote shutdown program
echo 5. Delete a computor (in progress)
echo 6. (Unfinished)
echo 7. (Unfinished)
echo 8. (Unfinished)
echo 9. (Unfinished)
echo 10. Exit
set /p choose=(1-9):
if %choose%==1 goto o1
if %choose%==2 goto o2
if %choose%==3 goto o3
if %choose%==4 goto o4
if %choose%==5 goto o5
if %choose%==6 goto close
if %choose%==7 goto close
if %choose%==8 goto close
if %choose%==9 goto close
if %choose%==10 goto o10
goto options
:close
cls
goto start
:o1
echo Stopping current command
del command.txt
echo. 2>command.txt
echo Command stopped!
pause
cls
goto start
I would greatly appreciate some help or comments to what I could do or add to this. Thanks!
Not an answer but several hints.
a variable can hold only single lines not a whole file.
if you want to get the first line of a file into a var use `Set /P "var="
set %textfile%=text.txt would store test.txt literally into a var whose name is the content of the var textfile.
you are mixing goto o1 and :01 with the label
`
My idea was to have it start when the computer boots and then ask me what game do I want to play. That's simple but I want to be able to answer different answers like: Is the input like CS:GO,cs,csgo,counter strike, and so forth and, here's how I tried to do it=
if %game%==1,CS:GO,cs:go,csgo,"Counter Strike","counter strike" goto cs
But as you probably know, it did not work. so the question is how to make it so that "%game%" can be a lot of different things and still goes to the same thing without having to do multiply if %GAME%==...?
and here's the whole code if you want to see it=
#echo off
color a
cls
:start
echo what game do you want to play?
echo 1/"CS:GO"? -"Counter Strike: Global Ofensive"
echo 2/"H&G"? -"Heros & Generals"
echo 3/"P2"? -"Portal 2"
echo 4/"UT"? -"Unturned"
echo 5/"LO"? -"Loadout"
echo 6/"DAB"? -"Double Action Boogaloo"
set /p game=vwhat game?:
if %game%==1,CS:GO,cs:go,csgo,"Counter Strike","counter strike" goto cs
pause
goto start
:start
echo what game do you want to play?
echo 1/"CS:GO"? -"Counter Strike: Global Ofensive"
echo 2/"H&G"? -"Heros & Generals"
echo 3/"P2"? -"Portal 2"
echo 4/"UT"? -"Unturned"
echo 5/"LO"? -"Loadout"
echo 6/"DAB"? -"Double Action Boogaloo"
set /p game=what game?:
echo /1/CS:GO/csgo/Counter Strike/ |find /i "/%game%/">nul && goto cs
rem other games here...
pause
goto start
/i makes the findcase insensitive, so it will find CSGO, CsGo, cSgO,...
&& works as "if previous command (find) was successful, then..."
I'm a new batch programmer and am creating a batch "start menu". I'm using the following text and it's saying "X" was not expected at this time. X was 1, game, text, and other things. I can't figure it out. HELP! I'm running XP SP3 and using the command prompt. Also, if anyone spots any other mistakes please inform me. e-mail me at superzemus#hotmail.com
cls
#echo off
echo Welcome to the Start Menu!
echo.
echo Press ctrl-z to exit. Press G to play Adventure. Press T to enter Text Editor.
pause
set Game= %gme%
set Text= %txt%
IF select Game goto gme
IF select Text goto txt
:txt
echo You have chosen to enter the Text editor.
pause
start edit
:gme
echo You have chosen to play Adventure.
pause
start C:\Adventure.exe
What you want here is probably either set /p:
set /p choice=Press ctrl-z to exit. Press G to play Adventure. Press T to enter Text Editor.
and then compare as follows:
if /i %choice%==G goto Game
if /i %choice%==T goto Text
goto :eof
Or use choice which doesn't require you to press Return:
choice /m "Press Q to exit. Press G to play Adventure. Press T to enter Text Editor." /c GTQ /n
if errorlevel 3 goto :eof
if errorlevel 2 goto Text
if errorlevel 1 goto Game
goto :eof
There is also another problem with your code: You should exit the batch file after starting the editor to avoid starting the game too:
:Text
start edit
goto :eof
:Game
rem That's a horrible place to put something
start C:\Adventure.exe
goto :eof