My switch
statement is not working properly when analysing a string variable.
The output and input are both 's.
HTML
<form name="interface">
<textarea name="output" rows="20" cols="100"></textarea><br>
<textarea name="input" rows="1" cols="100" onKeyDown="thinkInput(event);"></textarea>
</form>
JavaScript
function thinkInput(e)
{
if (e.keyCode == 13)
{
sInput = document.interface.input.value;
document.interface.output.value += sInput;
aInput = sInput.split(" ");
switch (aInput[0])
{
case "say":
textOut("You say \""+sInput.substring(aInput[0].length + 1)+"\"");
break;
case "move":
move(aInput[1]);
break;
default:
thinkFail();
break;
}
document.interface.input.value = null;
alert(aInput[0]);
}
}
I can see in my alert()
at the end that the case is either "say" or "move".
The first time I try to "say mudkipz" or "move around", everything works as I want it, but after that everything I type, thinkFail()
fires.