Help with Function Call for Dialogue System

Started by Custerly, Fri 08/12/2023 21:29:40

Previous topic - Next topic

Custerly

Hi all,

I am creating my own dialogue system, and having a lot of fun with it. I have it mostly working, but have hit a snag.

I have a dialogue GUI involving a label to display text, buttons for player dialogue choices, and a continue button to advance the npc dialogue when it's broken up into multiple text dumps. The 'continue' button adds +1 to a dislogue state integer that tells the dialogue function what text to spit out next, and then it runs the dialogue function which prints the text to the label and/or makes player choices visible (depending on the dialogue state).

That is all working well in my test scenario, however, in order for this system to scale, I need the continue button to be able to call diffeent functions depending on which conversation the player is currently engaged with. My idea was to have a string called 'CurrentDialogue' which will hold the name of the function for the current dialogue, and once the character clicks the character to start that dialogue, it will make 'CurrentDialogue' equal the name of the function for that character's dialogue. Then, on button click, I can call the function for the appropriate dialogue based on the value held in 'CurrentDialogue', only I don't see a way to actaully do that last part.

Any suggestions would be greatly appreciated.

Khris

AGS4 will support this iirc but current versions don't.

You'll have to implement this in a different way, for instance using structs. I imagine the dialog functions will all be relatively similar, which means you should be able to do this by making the referenced dialog data dynamic, as opposed to the function itself.

You can for instance use an array of structs, then store the array index in a variable, as opposed to the function name.

Minimal code example:

Code: ags
// header
struct Conversation {
  String options[10];
  bool active[10];
  int option_count;
  import bool AddOption(String text);
  import void Run();
};

// main

Conversation convo[5];

// game_start
  convo[0].AddOption("Hello");

// elsewhere
  convo[current_convo].Run();

Crimson Wizard

Saving functions in variables is not supported, but is in plans for the future.

I am not certain if this may be useful, but AGS 3.6.1 supports Dialog.GetByName() which returns Dialog* pointer by its script name.

Custerly

Thanks Khris and Crimson Wizard for taking the time to help out.

Khris: This is the first I'm learning of sctructs, but it does sound like this is probably the best / most efficient way of doing what I'm trying to do. I'll have to play around with structs now and figure it out.

Crimson Wizard: I've also enver encountered getbyname, so I'll have to look into that.

SMF spam blocked by CleanTalk