Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Ending dialogue in inner branch  (Read 2783 times)

0 Members and 1 Guest are viewing this topic.

jackslawed

  • Lurker
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 23
    • View Profile
Ending dialogue in inner branch
« on: June 25, 2010, 03:25:28 AM »

Hi all :)
I'm working on a dialogue puzzle, and I want the dialogue to end abruptly if the player chooses certain responses. This is no problem in the first branch, but on the inner branches it always returns to the previous dialogue (I'm using a modified version of the oldguy arrays from the WME demo.)

I found an old topic discussing this, and Metamorphium gave this response:
Quote
If you want then to in some inner branch cancel the whole dialogue you can use the following trick:

Code: [Select]

while (loop)
{
  ...
  ...
  Selected = Game.GetResponse();
 
  switch (Selected)
  {
    ...
    case 1:
      loop = SomeNextBranch();
      break;
    case 3:
      loop = false;
      break;
  }
 
}

And in the critical response of the inner branch you set return false; otherwise you return true. So when the SomeNextBranch ends with your terminal response, the loop will end too.

This seems to be what I'm looking for, but I'm a technical dunce, and don't really understand how to implement it. Not very clear on using the switch/case commands. What do we set "return false"?  The loop? A code snippet showing the inner branch would be really helpful.

Anyone able to explain this to a child? Is there any other way to just abort the dialogue using a simple command?
Thanks
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Ending dialogue in inner branch
« Reply #1 on: June 25, 2010, 07:48:34 AM »

Hello. First of all, since that time, I've discovered than using switch / breaks is kind of buggy inside of the loops so unfortunately you'll have to use if's for that.

Than you can set yourself a special value which would denote the end of the dialogue.


Code: WME Script
  1.  
  2. var selection = 0;
  3. while(selection != -1)
  4. {
  5.     ...
  6.     ...
  7.     selection = Game.GetResponse();   
  8.  
  9.     if (selection == 1)  selection = NextBranch();
  10.    
  11. }
  12.  
  13.  

This code established that we can override default loop value by the result of your NextBranch method, which could look like that.

Code: WME Script
  1.  
  2. function NextBranch()
  3. {
  4.      var selection = 0;
  5.      while(selection != -1)
  6.      {
  7.          ...
  8.          ...
  9.         selection = Game.GetResponse();   
  10.  
  11.         if (selection == 1) 
  12.              actor.Talk("Peaceful informative answer.");
  13.    
  14.         if (selection == 2) 
  15.         {
  16.              actor.Talk("Standard non abrupt ending");
  17.              selection = -1; // here we end up things peacefully, because the loop ends and 0 is returned from the method.     
  18.         }
  19.  
  20.         if (selection == 3) 
  21.         {
  22.              actor.Talk("Abrupt ending.");
  23.              return -1; // here we end up things abruptly. Instead of ending the loop, we immediately return from the function  with -1, which propagates into underlying method   
  24.         }
  25.  
  26.      }
  27.      
  28.      return 0;
  29. }
  30.  



Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

jackslawed

  • Lurker
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 23
    • View Profile
Re: Ending dialogue in inner branch
« Reply #2 on: June 26, 2010, 02:50:36 PM »

Thanks so much for the quick reply.
Tried it and after a bunch of my own stupid mistakes, it works great!
Thanks again
Logged
 

Page created in 0.071 seconds with 25 queries.