This is what I have so far
@echo off
:Ask
echo Would you like to use developer mode?(Y/N)
set INPUT=
set /P INPUT=Type input: %=%
If %INPUT%=="y" goto yes
If %INPUT%=="n" goto no
If %INPUT%=="Y" goto yes
If %INPUT%=="N" goto no
:yes
java -jar lib/RSBot-4030.jar -dev
echo Starting RSbot in developer mode
:no
java -jar lib/RSBot-4030.jar
echo Starting RSbot in regular mode
pause
Either way if the user enters y or n it always runs in -dev mode.
How do I make it run in -dev mode if the answer is yes, and regular mode if the answer is no. Also, how do I make it ask again if the input isn't Y, N, y, or n?
i just do :
Depending on the version of Windows you might find the use of the "Choice" option to be helpful. It is not supported in most if not all x64 versions as far as I can tell. A handy substitution called Choice.vbs along with examples of use can be found on SourceForge under the name Choice.zip
Here is a working example:
Add quotation marks (" ") around the %INPUT% so it looks like this:
I don't know the platform you're doing this on but I assume Windows due to the .bat extension.
Also I don't have a way to check this but this seems like the batch processor skips the If lines due to some errors and then executes the one with -dev.
You could try this by chaning the two jump targets (
:yes
and:no
) along with the code. If then the line without -dev is executed you know your If lines are erroneous.If so, please check if
==
is really the right way to do a comparison in.bat
files.Also, judging from the way bash does this stuff,
%foo=="y"
might evaluate to true only if%foo
includes the quotes. So maybe"%foo"=="y"
is the way to go.If the input is, say,
N
, your IF lines evaluate like this:That is, you are comparing
N
with"y"
, then"n"
etc. including"N"
. You are never going to get a match unless the user somehow decides to input"N"
or"y"
(i.e. either of the four characters, but enclosed in double quotes).So you need either to remove
"
from aroundy
,n
,Y
andN
or put them around%INPUT%
in your conditional statements. I would recommend the latter, because that way you would be escaping at least some of the characters that have special meaning in batch scripts (if the user managed to type them in). So, this is what you should get:By the way, you could reduce the number of conditions by applying the
/I
switch to theIF
statement, like this:The
/I
switch makes the comparisons case-insensitive, and so you don't need separate checks for different-case strings.One other issue is that, after the development mode command is executed, there's no jumping over the other command, and so, if the user agrees to run Java in the development mode, he'll get it run both in the development mode and the non-development mode. So maybe you need to add something like this to your script:
Finally, to address the issue of processing incorrect input, you could simply add another (unconditional)
goto
command just after the conditional statements, just before theyes
label, namelygoto Ask
, to return to the beginning of your script where the prompt is displayed and the input is requested, or you could also add another ECHO command before the jump, explaining that the input was incorrect, something like this:Note: Some of the issues mentioned here have also been addressed by @xmjx in their answer, which I fully acknowledge.