简体   繁体   English

如何将该功能添加到蝙蝠聊天机器人中?

[英]How can I add this feature to my bat chatbot?

This is my chatbot. 这是我的聊天机器人。 I would like to add that if the input is something different than "yes" and "no" then it should echo "Wrong answer". 我想补充一点,如果输入的内容不同于“是”和“否”,那么它应该回显“错误答案”。

@ECHO OFF
title Bane
:CHAT
SET /P input=Oh You think darkness is your ally? (yes or no) Your message:

IF %input%==yes ECHO That's were you're wrong!
IF %input%==no ECHO Admirable, but mistaken.
GOTO CHAT
:END
PAUSE
@ECHO OFF
title Bane
:CHAT
SET /P "input=Oh You think darkness is your ally? (yes or no) Your message: "
IF /i "%input%"=="yes" ECHO That's were you're wrong! & goto :end
IF /i "%input%"=="no" ECHO Admirable, but mistaken. & goto :end
echo wrong answer & goto :chat

:END
PAUSE

you might be interested in the choice command, which has it's own input verification: 您可能对choice命令感兴趣,它具有自己的输入验证:

@ECHO OFF
title Bane
:CHAT
choice /C YN /M "Oh You think darkness is your ally? Your message: "
if errorlevel 2 ECHO That's were you're wrong! & goto :end
if errorlevel 1 ECHO Admirable, but mistaken. & goto :end
echo wrong answer ; this line is never reached

:END
PAUSE

In the second code example I removed (yes or no) , as choice already prints out all valid choices. 在第二个代码示例中,我删除了(yes or no) ,因为choice已经打印出了所有有效的选择。 But of course you can keep it and supress default choices wihth /n (thanks, Compo, valid argument): 但当然您可以保留它,并在/n禁止默认选项(感谢,Compo,有效参数):

`choice /C YN /N /M "Oh You think darkness is your ally? (yes or no) Your message: "`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM