Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: Bugs concerning the switch statement  (Read 8683 times)

0 Members and 1 Guest are viewing this topic.

ronin

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 8
    • View Profile
Bugs concerning the switch statement
« on: January 07, 2009, 01:14:37 PM »

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.
Code: WME Script
  1. global StateChair;
  2.  
  3. on "LeftClick"
  4. {
  5.     actor.GoToObject(this);
  6.     Game.Interactive = false;
  7.        
  8.     switch (GUIInterfaceButton)
  9.     {
  10.         case BUTTON_LOOKAT:
  11.         {
  12.             switch (StateChair.LookedAt)
  13.             {
  14.                 case 1:
  15.                 {
  16.                     actor.Talk("Looking the second time at the chair.");
  17.                     StateChair.LookedAt = StateChair.LookedAt + 1;
  18.                     break;
  19.                 }
  20.                                
  21.                 case 2:
  22.                 {
  23.                     actor.Talk("Looking the third time at the chair.");
  24.                     StateChair.LookedAt = StateChair.LookedAt + 1;
  25.                     break;
  26.                 }
  27.                                
  28.                 case 3:
  29.                 {
  30.                     actor.Talk("Looking at the chair again and again.");
  31.                     break;
  32.                 }
  33.                                
  34.                 default:
  35.                 {
  36.                     actor.Talk("Looking the first time at the chair.");
  37.                     StateChair.LookedAt = 1;
  38.                 }
  39.             }
  40.             break; // This break causes an error!
  41.         }
  42.                
  43.         case BUTTON_TAKE:
  44.         {
  45.             // some code
  46.             break;
  47.         }
  48.                
  49.         case BUTTON_TALK:
  50.         {
  51.             // some code
  52.             break;
  53.         }
  54.                
  55.         case BUTTON_USE:
  56.         {
  57.             // some code
  58.             break;
  59.         }
  60.     }
  61.  
  62.     Game.Interactive = true;
  63. }
  64.  

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.
Code: WME Script
  1. on "LeftClick"
  2. {
  3.     actor.GoToObject(this);
  4.     Game.Interactive = false;
  5.  
  6.     switch (GUIInterfaceButton)
  7.     {
  8.         case BUTTON_LOOKAT:
  9.         {
  10.             // some code
  11.             break;
  12.         }
  13.                
  14.         case BUTTON_TAKE:
  15.         {
  16.             Game.PlaySound("sfx/soundeffect.ogg");
  17.             while (Game.IsSoundPlaying("sfx/soundeffect.ogg"))
  18.             {
  19.                 Sleep(1);
  20.             }
  21.             break; // This break causes an error!
  22.         }
  23.                
  24.         case BUTTON_TALK:
  25.         {
  26.             // some code
  27.             break;
  28.         }
  29.                
  30.         case BUTTON_USE:
  31.         {
  32.             // some code
  33.             break;
  34.         }
  35.     }
  36.        
  37.     Game.Interactive = true;
  38. }
  39.  

I also tested the equivalent if/else if/else-constructions and they worked perfectly.
« Last Edit: January 07, 2009, 10:58:54 PM by ronin »
Logged

odnorf

  • w00t?
  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 7
  • Offline Offline
  • Gender: Male
  • Posts: 1456
  • Lamp dog!
    • View Profile
Re: Bugs concerning the switch statement
« Reply #1 on: January 14, 2009, 10:56:37 PM »

Those are known bugs of the script compiler and to fix them would require massive work. They are already fixed in wme2 script compiler but that's a complete rewrite and not compatible.
Logged
fl*p

Jose

  • Regular poster
  • ***
  • Karma: 2
  • Offline Offline
  • Posts: 134
    • View Profile
Re: Bugs concerning the switch statement
« Reply #2 on: April 04, 2009, 03:30:41 PM »

So, is there any work-around or we must use the if/else construction a forget about using switch statements until WME2?

Thanks.
Logged

Akusa

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 46
    • View Profile
Re: Bugs concerning the switch statement
« Reply #3 on: April 04, 2009, 04:25:23 PM »

Indeed there is a work arround that also increases the readability of your code:
you can simply create every tree Node as a function.

For example:

Code: [Select]
on "abc"
{
   switch(something)
   {
      case 1:
      {
         NodeA();
         break;
      }
      case 2:
         NodeB();
         break;
      }
   }
}

function NodeA()
{
   switch(something)
   {
      case 1:
      {
         NodeC();
         break;
      }
      case 2:
         NodeD();
         break;
      }
   }
}

function NodeB()
{
   switch(something)
   {
      case 1:
      {
         NodeE();
         break;
      }
      case 2:
         NodeF();
         break;
      }
   }
}
« Last Edit: April 04, 2009, 04:27:13 PM by Akusa »
Logged

Jose

  • Regular poster
  • ***
  • Karma: 2
  • Offline Offline
  • Posts: 134
    • View Profile
Re: Bugs concerning the switch statement
« Reply #4 on: April 04, 2009, 04:35:54 PM »

Thank You Akusa
Logged
 

Page created in 0.032 seconds with 25 queries.