During evaluating version 1.8.8 (Beta) of the WME i found two bugs concerning the switch statement. I have added two simplified code examples for better understanding.
1. If two switch statements are nested the outer break-command causes an error (Fatal: Invalid instruction -557797922).
Example: Left clicking on a scene object (a chair) after the "Look At" Button has been pressed. Depending on how often the player has looked at the chair the actor speaks different lines.
global StateChair;
on "LeftClick"
{
switch (GUIInterfaceButton)
{
case BUTTON_LOOKAT:
{
switch (StateChair.LookedAt)
{
case 1:
{
actor.
Talk("Looking the second time at the chair.");
StateChair.LookedAt = StateChair.LookedAt + 1;
break;
}
case 2:
{
actor.
Talk("Looking the third time at the chair.");
StateChair.LookedAt = StateChair.LookedAt + 1;
break;
}
case 3:
{
actor.
Talk("Looking at the chair again and again.");
break;
}
default:
{
actor.
Talk("Looking the first time at the chair.");
StateChair.LookedAt = 1;
}
}
break; // This break causes an error!
}
case BUTTON_TAKE:
{
// some code
break;
}
case BUTTON_TALK:
{
// some code
break;
}
case BUTTON_USE:
{
// some code
break;
}
}
}
2. If a while loop is used inside a case the break-command at the end of the case causes the same error.
Example: Hold the script while playing a certain soundfile.
on "LeftClick"
{
switch (GUIInterfaceButton)
{
case BUTTON_LOOKAT:
{
// some code
break;
}
case BUTTON_TAKE:
{
{
}
break; // This break causes an error!
}
case BUTTON_TALK:
{
// some code
break;
}
case BUTTON_USE:
{
// some code
break;
}
}
}
I also tested the equivalent if/else if/else-constructions and they worked perfectly.