C# 引起聊天机器人的注意
我已经试着寻找最好的方法,但我不太确定该搜索什么;所以如果有人介意的话,我希望能得到一些帮助 在我的C#表格中,我有:C# 引起聊天机器人的注意,c#,if-statement,chat,C#,If Statement,Chat,我已经试着寻找最好的方法,但我不太确定该搜索什么;所以如果有人介意的话,我希望能得到一些帮助 在我的C#表格中,我有: 输入文本框 输出文本框 我正在使用“InputTextbox\u KeyDown”来运行越来越多的“if”语句。即: if (e.KeyCode == Keys.Enter & InputputTextbox.Text.Contains("hello") OutputTextbox.Text = "hi there" 我将聊天机器人称为“Penny”,希望它在输入
- 输入文本框
- 输出文本框
if (e.KeyCode == Keys.Enter & InputputTextbox.Text.Contains("hello")
OutputTextbox.Text = "hi there"
我将聊天机器人称为“Penny”,希望它在输入文本框中输入单词“Penny”后只查找进一步的命令。(即:如果用户键入“hello”,则不会发生任何事情,因为他们没有得到“Penny”的注意)
大概是这样的:
if (KeyCode == Keys.Enter & InputTextbox.Text.Contains("penny")
then
*look for the next InputTextbox.Text*
这有什么意义吗?您只需设置一个标志,指示输入了“penny”
private bool _isActive = false;
public void YourMethod()
{
if (!_isActive)
{
if (KeyCode == Keys.Enter && InputTextbox.Text.Contains("penny"))
{
_isActive = true;
}
}
else
{
if (e.KeyCode == Keys.Enter && InputputTextbox.Text.Contains("hello"))
{
OutputTextbox.Text = "hi there";
}
// other if's
}
}
你不能把这个放在你的InputExtBox\u键下方法的顶部吗
if(KeyCode != Keys.Enter) return;
if(!InputTextbox.Text.Contains("penny")) return;
/*
* rest of chat responses
*/
这有什么意义吗?不是真的…对不起。啊。。。基本上,我希望程序只在短语“penny”输入InputTextbox并回复“hi there”后执行命令。我已经编辑了您的标题。请看,“,其中的共识是“不,他们不应该”。问题是什么?如果你尝试了一些不起作用的东西,告诉我们它以什么方式不起作用