2012-10-23 4 views
1

그래서 여기에 내가하려고하는 것이 있습니다. 솔직히 말해서, 그것이 분명해야한다고 생각합니다. 그러나 그것을 이해할 수는 없습니다. 매우 간단한 인공 지능 시뮬레이션을 만들고 있습니다. 그리고이 시뮬레이션에는 화면 하단에 입력 상자가 있습니다 (정확히 "입력"이라고 함). "input"은 속성에 "inbox"(정확하게)라는 변수가 있습니다. 키 리스너를 사용하여 Enter 버튼을 누르면 스크립트가 기능을 호출합니다. 이 함수에는 2 개의 if 문과 AI ("nistra")라는 응답을 지시하는 else 문이 있습니다. 문제는 이것입니다. 내가 말하고자하는 내용을 입력하고 Enter 키를 누르면 항상 두 번째 응답 (아래 코드에서 "lockpick")이 사용됩니다. 코드에 변형을 시도했지만 여전히 해결책을 찾지 못했습니다. 문제는 "typein"변수가 변수뿐만 아니라 텍스트 상자의 모든 형식 정보를 보유하고 있다고 생각하지만 잘못된 정보 일 수 있습니다. 정보는 코드 자체 아래에 있습니다. 내가 얻을 수있는 도움은 크게 감사 할 것입니다.actionscript 2.0 입력 텍스트 상자

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는"나는 당신이 동등 비교를 위해 == 대신 =를 사용할 필요가 있음을 확신 추적합니다 ECMAScript를 기반으로 액션부터 다음

<TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="Times New Roman" SIZE="20" COLOR="#FF0000" LETTERSPACING="0" KERNING="0">test</FONT></P></TEXTFORMAT> 

답변

0

.

는 현재 코드는 다음과 같이 작동합니다

if(typein = "Hello") { // assign "Hello" to typein. always true. 
    respond = "Hello, How are you?"; 
} 
if(typein = "lockpick") { // assign "lockpick" tot ypein. always true. 
    respond = "Affirmative"; 
} 
// the else block is always false for obvious reasons 

그래서 당신은 단순히 같은 코드를 변경해야합니다

단순히 응답 시작 그 변화를 사용하여 작동하지 않았다 불행하게도
if(typein == "Hello") { 
    respond = "Hello, How are you?"; 
} 
else if(typein == "lockpick") { 
    respond = "Affirmative"; 
} 
else { 
    respond = "I do not understand the command, please rephrase"; 
} 
+0

, 다른 사건을 가진 모든 것에. "난 이해가 안 돼요". 그것이 올바른 입력이라 할지라도. – user1769760

+0

또한 내가 추적 한 내용을 수정했다는 점을 지적하고 싶습니다. 처음 질문을 올렸을 때 잘못된 정보를 붙여 넣는 것처럼 보였습니다. – user1769760

+0

좋아, 지금은 그걸로 놀고있어, 명령을 입력하지 않고도 본질적으로 똑같은 3 버튼을 추가했습니다. 다음은 버튼 코드입니다. b_hello.onRelease = function() { \t typein = "Hello"; \t nistraresponse(); \t trace ("calling"); } b_lock.onRelease = function() { \t typein = "lockpick"; \t nistraresponse(); } b_dontunderstand.onRelease = function() { \t typein = "이해하지 못함"; \t nistraresponse(); } 이 올바르게 작동합니다 – user1769760

관련 문제