Batch DOS

March 21, 2010 at 14:12:13
Specs: Windows Vista
Hello. I'm making a chat bot for school and it's going pretty good but I have this one problem. How do I make a shortcut for the IF statements? Is there anything like:
if "%input%"=="hello" or "Hello" or "hi" or "Hi" (ECHO Hello %name%! & GOTO WN)

See More: Batch DOS

Report •

March 22, 2010 at 03:11:14
I don't clearly understand what you need, but if you want the IF ignores uppercase/lowercase characters add the /I switch, so

if /I "%input%"=="hello" (echo Hello %name%! & goto :WN)

Report •

March 22, 2010 at 14:15:07
Thanks! That wasn't what I was looking for but that's much more easier than what I wanted!

I have another problem.
if /i "%input%"=="hi %botname%" (echo "Hello" & pause)
I want the script respond to "Hi %botname%" because the bot's name is given by the user

Report •

March 23, 2010 at 08:05:44
Sorry IZRBoD,

again it is not clear to me what you want to achieve, so take the following as a sample.

set /P name=Please, enter your name^>

:: here the code to check if the user is allowed to continue

type names.txt | find /I "%name%" > nul
if not ErrorLevel 1 (
  echo.  Hello %name%, press any key to continue...
) else (
  echo.  Sorry "%name%" is unknown & goto :EOF
pause > nul

names.txt is a text file holding the names (nicknames) of users allowed to enter the application and must have the following layout, e.g.

Liz Ashley
Tom Osborne
i.e. one name on each line.

You can edit the file by its own without modifying the associated batch. As I said this is just a tip. I hope this can help.

Report •

Related Solutions

March 23, 2010 at 15:56:41
I already know how to do that.
I want the user to say the bot's name and the bot will respond to the user. Lets say that the user said that the bot's name is Bob so

set aimname=
set /P botname=Chat Bot's name: %=%
:: user inputs name here as "Bob"

set input=
set /P input=%name%: %=%
:: user said "Hi Bob"
if "%input%"=="" goto inputhello
if /i "%input%"=="hi %botname%" (echo "Hello" & goto menu)

The problem is, "bob" doesn't respond back

Report •

March 24, 2010 at 14:03:34
I can't reproduce your issue using the posted code. There is just the variable %name% that is undefined, but I guess you assigned that in another section of the script.

So far your problem remains mysterious for me.

Report •

March 24, 2010 at 17:01:37
Ok, let me try again

set name=
set /P name=Your name: %=%
if "%name%"=="" goto yourname
::user inputs name here as "George"

set botname=
set /P botname=Chat Bot's name: %=%
if "%botname%"=="" goto botname
:: user inputs name here as "Bob"

set input=
set /P input=%name%: %=%
:: user inputs "Hi Bob"
if "%input%"=="" goto inputhello
if /i "%input%"=="hi %botname%" (echo "%botname%: Hello" & goto menu)
::Bob should say "Bob: Hello" here

"Bob" won't say "Bob: Hello" to "George" when George inputs "hi Bob". Is there a way for Bob to say something back to George when George says Bob's name?

Report •

March 25, 2010 at 04:29:25
What you report is absolutely clear and again I saved and run the code you displayed in the previous post according to the suggested conversation between George and Bob.

Unfortunately the script runs perfectly under my systems (Windows XP/Vista/7) with any blend of uppercase/lowercase characters.

The one thing I can figure out is some unwanted mismatch in the entered strings as trailing, leading or embedded spaces, e.g. "hi Bob ", as the compared strings must exactly match.

I have a strong know-how and practical experience in batch scripting but this is a X-File case.
Glad to help but How?

Report •

Ask Question