Solved Why does my batch file keep redirecting

Dell Inspiron black 15r notebook
August 5, 2013 at 13:14:30
Specs: Windows 7, N/A
Okay so I'm making a batch rpg and everything is awesome except. When I type in the corresponding number to goto the label I want to it keeps going to another one I didn't tell it too I tried everything to fix it. HELP! D:

Code:

@echo off
set money=10000
:start
cls
echo W E L C O M E T O R.P.G
set /p user=Enter A Username:
goto title

:title
cls
echo Welcome %user%!


echo 1.Start R.P.G
echo 2.Settings
echo 3.Logout
set /p choice=
if %choice%==1 goto settings
if %choice%==2 goto main
if %choice%==3 goto logout

:main
echo Logged in as %user% Money Balance %money%


:settings
cls
echo Settings

echo 2.) Change color
set /p collor=
if %collor%==1 goto cc

:cc
cls
echo hat color would you like it to be?

echo See below for easy color change

echo 1. Red
echo 2. Green
echo 3. Blue
set /p cc=
if %cc%==1 goto cc2
if %cc%==2 goto cc3
if %cc%==3 goto cc4
if %cc%==4 goto cc1
:cc1
set /p coo=Color Code:
pause>nul
echo When done press enter
goto title
:cc2
cls
color 4
goto title
:cc3
cls
color 2
goto title
:cc4
cls
color 1
goto title

:logout
goto start


See More: Why does my batch file keep redirecting

Report •


✔ Best Answer
August 6, 2013 at 13:36:57
I'm glad you have figured it out.

Law of Logical Argument: Anything is possible if you don't know what you're talking about.



#1
August 6, 2013 at 07:13:46
Looks like your options don't match where they take you.

This is what you have:

echo 1.Start R.P.G
echo 2.Settings
echo 3.Logout
set /p choice=
if %choice%==1 goto settings
if %choice%==2 goto main
if %choice%==3 goto logout


This is what I think it should be:

echo 1.Start R.P.G
echo 2.Settings
echo 3.Logout
set /p choice=
if %choice%==1 goto main
if %choice%==2 goto settings
if %choice%==3 goto logout

Notice 'main' and 'settings' were switched around.

Law of Logical Argument: Anything is possible if you don't know what you're talking about.


Report •

#2
August 6, 2013 at 07:20:22
Also, at the end of each "section" you need to tell it where to go next otherwise it will just go in order until it gets to the end of the script.

For instance, the way your script is set up now, if you use the menu option to goto 'main' it will continue into 'settings.' If you don't want that to happen, you will need to put a 'goto' statement at the end of 'main.'

I didn't run your script, so I don't know what it looks like, but don't forget you can also use 'pause' or 'pause>nul' to pause the script. Pause>nul is nice because you can put your own text above it and it suppresses the "Press any key to continue" dialogue. You can then press any key to resume the script.

Law of Logical Argument: Anything is possible if you don't know what you're talking about.


Report •

#3
August 6, 2013 at 11:04:10
That's what it looks like But I forgot to show the changes I made. It's been doing that since I directed it to main

Report •

Related Solutions

#4
August 6, 2013 at 11:32:35
See my second post. Unless you tell it where to go next, the script will just keep going in order from top to bottom. If after 'Main' you don't want it to continue on to 'Settings', you will need to insert a goto statement at the end of 'Main.'

For example:

:main
echo Logged in as %user% Money Balance %money% 
goto cc

The above code will skip 'Settings' after completing 'Main' and go right to 'cc.'

Law of Logical Argument: Anything is possible if you don't know what you're talking about.


Report •

#5
August 6, 2013 at 13:24:57
%CC% is my color change input

Report •

#6
August 6, 2013 at 13:31:55
Thanks Man :D I fixed it. Turns out I just needed to rename the label to something besides Settings

Report •

#7
August 6, 2013 at 13:33:04
It doesn't make any diference to me. Do you get what I'm trying to explain?

Law of Logical Argument: Anything is possible if you don't know what you're talking about.


Report •

#8
August 6, 2013 at 13:36:57
✔ Best Answer
I'm glad you have figured it out.

Law of Logical Argument: Anything is possible if you don't know what you're talking about.


Report •

#9
August 6, 2013 at 13:49:50
Code:
@echo off
set money=10000
:start
cls
echo W E L C O M E T O R.P.G
set /p user=Enter A Username:
goto title
:title
cls
echo Welcome %user%!

echo 1.Start R.P.G
echo 2.Settings
echo 3.Logout
set /p choice=
if %choice%==1 goto main
if %choice%==2 goto settings
if %choice%==3 goto logout
:main
echo Logged in as %user% Money Balance %money%

::edited for information
echo more development to come
pause
goto title
::edited for information

:settings
cls
echo Settings
echo 2.) Change color
set /p collor=
if %collor%==2 goto cc
::edited
goto settings
::edited
:cc
cls
echo hat color would you like it to be?
echo See below for easy color change
echo 1. Red
echo 2. Green
echo 3. Blue
set /p cc=
if %cc%==1 goto cc2
if %cc%==2 goto cc3
if %cc%==3 goto cc4
echo please select a valid color && pause && goto cc
::not sure what the intent was
:cc1
set /p coo="Color Code: "
pause>nul
echo When done press enter
::blocking it out for convience
:cc2
cls
color 4
goto title
:cc3
cls
color 2
goto title
:cc4
cls
color 1
goto title

:logout
echo you have reached the logout point
set /p locheck="y for logout"
if %locheck% equ y goto exit
goto start
:exit
cls

:: mike


Report •


Ask Question