所以,这就是我想要做的,坦率地说,我相信这应该是显而易见的,但我无法弄清楚。我正在创建一个非常简单的人工智能模拟。在这个模拟中,屏幕底部有一个输入框(精确地称为“输入”)。“输入”在其属性中有一个变量,称为“收件箱”(确切地说)。使用按键侦听器,脚本在按下回车按钮时调用一个函数。该函数有 2 个 if 语句和一个 else 语句,它们指示 AI 的响应(名为“nistra”)。问题是,当我输入我想说的话,然后按回车键时,它总是使用第二个响应(下面代码中的“lockpick”)。我已经尝试了代码的变体,但我仍然没有看到解决方案。我认为问题在于“typein”变量包含来自文本框以及变量的所有格式信息,但我可能错了,该信息也在这里,位于代码本身的下方。我能得到的任何帮助将不胜感激。
var typein = ""; //copies the text from inbox into here, this is what nistra responds to
var inbox = ""; //this is where the text from the input text box goes
var respond = ""; //nistra's responses go here
my_listener = new Object(); // key listener
my_listener.onKeyDown = function()
{
if(Key.isDown(13)) //enter button pressed
{
typein = inbox; // moves inbox into typein
nistraresponse(); // calles nistra's responses
}
//code = Key.getCode();
//trace ("Key pressed = " + code);
}
Key.addListener(my_listener); // key listener ends here
nistraresponse = function() // nistra's responses
{
trace(typein); // trace out what "typein" holds
if(typein = "Hello") // if you type in "Hello"
{
respond = "Hello, How are you?";
}
if(typein = "lockpick") // if you type in "lockpick"
{
respond = "Affirmative";
}
else // anything else
{
respond = "I do not understand the command, please rephrase";
}
cntxtID = setInterval(clearnistra, 5000); // calls the function that clears out nistra's response box so that her responses don't just sit there
}
clearnistra = function() // clears her respond box
{
respond = "";
clearInterval(cntxtID);
}
// "typein" 跟踪以下内容
<TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="Times New Roman" SIZE="20" COLOR="#FF0000" LETTERSPACING="0" KERNING="0">test</FONT></P></TEXTFORMAT>