I am making a chatterbot. (A robot you can talk to.) So I need to collect user input. Im using the "set /p variable=You Say: " When the user has given his/her imput it is stored as "%variable%". I then use the "IF %variable%==no ECHO I see." which allows the robot to respond if the variable is reconised but is the variable is larger than one word say "how are you" I then would use "IF %variable%==how are you ECHO Fine, thanks." the MS-DOS closes! What can I do?
2007-04-11
08:51:44
·
6 answers
·
asked by
Cal R
2
in
Computers & Internet
➔ Programming & Design
No, I have got a GOTO :START so that it wont run out of commands. It works when the variable is one word but not more that one!
2007-04-11
09:17:07 ·
update #1
I think your batch file is closing because once it gives you your resut (of "Fine, Thanks.") the batch file has no more commands, so it assumes it is at the end. Try adding your 'set /p variable=You Say' command again after the response is given. Once they have asked a question, and given a response, they need to be able to input another command/question, this will keep the batch running, and allow for multiple interactions during the same session. You will need to program in an exit command though, to close out the conversation and batch when your done talking to the AI program.
ADDED 4/11/07 7:40pm: After reading your 'comments' response, I've played around with your commands. I figure the space is throwing off the command. This is what I've done and it's working well for me.
@ECHO OFF
:START
set /p variable=You Say:
set userinput="%variable%"
IF %userinput%=="how are you" ECHO Fine
IF %userinput%=="no" ECHO I see.
GOTO START
Basically, I am taking the variable you are getting, and wrapping it in quotes (changing the variable to userinput, and warpping the quotes during this set). Then in the IF statments, wrap the 'user commands' in quotes, and it will reconize these and prompt the correct phrase and then ask the You Say again. The code block above is an exact copy of what I've been doing, and its working well on my end.
2007-04-11 09:07:50
·
answer #1
·
answered by thirteenth13_dimension 1
·
2⤊
0⤋
How are you running it? Are in XP or something and are just double clicking on the .bat file? When you double click a .bat in XP it will open a command prompt and close as soon as the .bat has run out of instructions. What I'm thinking is it is printing the last line then closing before you can read it. Try running it for a command prompt instead of just double clicking. (Start>Run>"cmd" Then navigate to the bat and then run it. If I'm right, you'll end with a prompt with the output above so you can review)
2007-04-11 09:07:32
·
answer #2
·
answered by Joe R 3
·
0⤊
1⤋
first of all, why in the world are you doing this in a batch file? seems like a general-purpose language like java would be a better fit.
anyway, maybe you need to add a 'call' statement before the 'echo' command? sometimes batch files will exit unless you add the 'call' command.
2007-04-11 09:45:43
·
answer #3
·
answered by fixedinseattle 4
·
0⤊
0⤋
Seems like you need to need to establish, if %varible% = "Hello" first, if not ..is it an input varible Therefore. if I do not type in Hello,, then your ELSE statemnt will Echo your response statement. My thinking is that your IF statement will end and that it. I think you will need a nested IF Statment to loop, otherwise, your program will quit regardless of answer. Becareful not to get stuck in an ENDLESS LOOP. Good luck.
2016-05-17 21:34:16
·
answer #4
·
answered by leah 3
·
0⤊
0⤋
You cant put spaces in if statements for the result, it would just be if you typed "How"
2014-03-31 13:11:42
·
answer #5
·
answered by ? 1
·
0⤊
0⤋
Not really understanding what the problem is. Can you elaborate...
2007-04-11 09:00:45
·
answer #6
·
answered by 7S282 4
·
0⤊
2⤋