How to have three or more potential dialogues for one character?

Started by timebandit, Wed 06/01/2021 19:13:13

Previous topic - Next topic

timebandit

I have bumped into a problem with enabling different dialogues depending on what the player has done before.

What I've written looks something like this:

Code: ags

function cMan_Interact()
{
  if (dWoman1.HasOptionBeenChosen(3))
  {
  dMan2.Start();
  }
    else if (dSnake1.HasOptionBeenChosen(1))
  {
    dMan3.Start();
    }
    else if (dSnake.HasOptionBeenChosen(2))
    {
      dMan4.Start();
    }
    else {dMan.Start();}
}


This script works well for having cMan change from dMan1 to dMan2 if the player has talked to cWoman.

However, while I can run the game without any error notification, the player is unable to get the dMan3 dialogue, which is the dialogue that I want to have activated after dSnake1.

I assume that the problem is that the script "thinks" something like this:

"The player has had dWoman1, therefore dMan2 will forever be the dialogue that the player has with cMan."

How do I change my script so that dSnake1 will enable dMan3 and disable dMan2?

Crimson Wizard

Change the order of conditions to check ones that replace others first.

EDIT:
Ok, more on this.

The real question is, does dSnake1 condition assume dWoman1 condition is also true, or are these parallel? Are these sequential stages of a game, or they may happen in any order?
In situation like this it's better to first write stages logic down "on paper". Without that it will be impossible to give accurate solutions.

heltenjon

Try putting the most radical change first. From what you write, I guess if you check for dSnake1 first, it should activate dMan3. If that's right, you can solve the problem by swapping places - checking first for dSnake, then dSnake1, then dWoman1.

timebandit

Okay, I believe I have fixed it now thanks to your help.

Let me first say that I made a typo in my original post, I meant to write "dSnake2", not just "dSnake".

Like you have already said, my mistake was that I wrote most of it in the wrong order. I was wrong to assume that the problem was because of something specifically related to dWoman1.

So I guess that means that, if you want any amount of potential dialogue, whether it is 2, 3 or higher, you have to put the "ultimate" dialogue first. A potential dialogue has to be younger than the dialogue below it, and older than the dialogue above it. So the fix to my problem is simply this:

Code: ags

function cMan_Interact()
    else if (dSnake2.HasOptionBeenChosen(2))
    {
      dMan4.Start();
    }
    else if (dSnake1.HasOptionBeenChosen(1))
  {
    dMan3.Start();
    }
{
  if (dWoman1.HasOptionBeenChosen(3))
  {dMan2.Start();}
    else {dMan.Start();}}


Thanks to both of you for your help!

heltenjon

Quote from: timebandit on Wed 06/01/2021 21:41:53
So I guess that means that, if you want any amount of potential dialogue, whether it is 2, 3 or higher, you have to put the "ultimate" dialogue first. A potential dialogue has to be younger than the dialogue below it, and older than the dialogue above it.

Have to is stressing it, but it's probably the easiest way. You could perhaps make a dWoman string change to false when the option that replaces it is chosen - the gaffa tape method.  :-D I think your original code would work fine if the options were mutually exclusive. (Like if you choose a class for your character in the start of the game and want different responses given to a wizard and a warrior.)

Khris

If you use the NOT operator, you can keep the chronological order in your script:

Code: ags
function cMan_Interact() {

  if (!dWoman1.HasOptionBeenChosen(3)) dMan.Start();
  else {
    // dWoman #3 has been chosen
    if (!dSnake1.HasOptionBeenChosen(1)) dMan2.Start();
    else {
      // dSnake1 #1 has been chosen
      if (!dSnake2.HasOptionBeenChosen(2)) dMan3.Start();
      // dSnake2 #2 has been chosen
      else dMan4.Start();
    }
  }
}


The nesting (and proper indentation) also makes it clear how the execution will branch and makes the code easier to maintain.

SMF spam blocked by CleanTalk