What would be the correct way to make dialogue greetings change?

Started by Gal Shemesh, Fri 14/07/2023 17:27:19

Previous topic - Next topic

Gal Shemesh

Hi everyone,

Been reading about dialogues in AGS in a few places, but can't find information on this topic:

I would like to have my characters greet each other for the first time they talk, but on their second talk and on I wish their greetings (whatever I write within the @S of the first dialogue) to change, as they already know each other.

What would be the correct way to doing this? I'm thinking about making a bool of 'wasTalkedWith' for each NPC, which will launch the first dialogue when the players talk with other characters, and then to turn it to true. Then, any further talk to the other NPC will launch a different greeting dialogue with an 'already know each other' greetings.

Is this the right way to doing this? Or perhaps there's a simpler way to change the @S greetings of a given dialogue?

Thanks
Gal Shemesh,
goldeng

Matti

Yes, either make a bool that changes the dialog*, or use a String variable that directly changes the greeting text of the two.

* You don't have to switch to another dialog. In dialogs you can use normal script, so in @S you could write something like this (with indented lines):

if (wasTalkedWith)
{
  characterA.Say("Hi friend!");
  characterB.Say("Nice to see you.");
}
else
{
  characterA.Say("Hello, Stranger.");
  characterB.Say("Hello.");
}

Gal Shemesh

Thanks @Matti! :)

Using the regular scripting in dialogues with indentation to make the players talk works great. Though, I found that the dialogue scripting commands work with if statements as well, so I put an if statement that checks if wasTalkedWith_Josh is false, which then greets the NPC for a first time greeting using Ego: "Hi!". And then I added an else statement to it, which then greets the NPC with an "already know each other" message.

The problem I found however is that when using the regular dialogues commands, such as return, goto-dialog, etc within the if statement, it gives an error as if these commands "break" the if statement before it ended. And so it gives this error:

Script commands can only be used in the area between a entry point and the closing return/stop statement.

Any way of using if statements along with the regular scripting commands to return to options or to jump to other dialogues, instead of starting a different dialogue manually the traditional way with indentation?
Gal Shemesh,
goldeng

Khris

It should work if you don't indent the dialog script commands. Like

Code: ags
  if (wasTalkedWith_Josh) {
Ego: Hi again!
goto-dialog 3
  } else {
Ego: Hi, how are you?
    wasTalkedWith_Josh = true;
  }

Gal Shemesh

Thanks, @Khris! Not sure what I'm doing wrong. I still can't make it to work. Here's my code. It still gives me the error: Script commands can only be used in the area between a entry point and the closing return/stop statement

Code: ags
// Dialog script file
@S  // Dialog startup entry point
  if (wasTalkedWith_cJosh)
  {
Ego: Hello again.
  cJosh.Loop = 1;
  Wait(20);
Josh: Oh, hi Roger.
goto-dialog dDialog2
  }
  else
  {
Ego: Hi!
  cJosh.Loop = 1;
  Wait(40);
Josh: Hello.
return
  }

@1
  Wait(20);
Josh: Hi Roger! Name's Josh. Nice to meet you.
  wasTalkedWith_cJosh = true;
goto-dialog dDialog2

@2
  Wait(20);
Josh: No worries.
  cJosh.Loop = 0;
stop
Gal Shemesh,
goldeng

Matti

I think the return in line 17 should come after the closing bracket in line 18.

Also good to know that script commands can be combined with dialog commands, I wasn't sure about that.

Gal Shemesh

Thanks @Matti!

I moved the "return" command after the last closing curly brackets and it works. But it doesn't work for "goto-dialog" which comes before it, so I need to use "dDialog2.start()" instead.

A little confusing - I thought that these commands need to come inside the curly brackets as they're part of the statements.

Anyway, thanks again! :)
Gal Shemesh,
goldeng

Crimson Wizard

If I recall correctly, you may still use "return" inside the brackets, if you indent and return a proper code:
https://adventuregamestudio.github.io/ags-manual/DialogScript.html#using-regular-scripting-commands-in-dialogs

QuoteIf you want to conditionally break out of the dialog script, the special tokens RUN_DIALOG_GOTO_PREVIOUS, RUN_DIALOG_RETURN and RUN_DIALOG_STOP_DIALOG are available which you can return from inside a script block

Gal Shemesh

Awesome! Thanks @Crimson Wizard! You were one step ahead of me before I asked a further question - I just tried to make my function to start with the false state, and encountered with the problem that the return command which I had to put into the statement's brackets didn't work. Now with return RUN_DIALOG_RETURN; I can actually use it within the brackets. Though, I see that there is no parallel token for the goto-dialog command, so I have to use "dDialog2.start()" instead.

Anyway, I think that when using the unique dialogue script commands that it's all a matter of where you locate your statements in the code - sometimes it makes more sense to write them from end to start, and sometimes it's the other way around.
Gal Shemesh,
goldeng

SMF spam blocked by CleanTalk