Page 1 of 1

Executing multiple functions after a dialogue choice is made

Posted: Fri Jan 28, 2022 7:17 am
by sunwooz
Hello!

I'm having a blast getting the dialogue system up and running for my game, but I'm having a lot of trouble trying to figure out how to execute multiple scripts when a dialogue choice is made.

I have an animation function that makes the character leave the screen after the dialogue ends, so I used a sendMessage function to call my "CharacterLeave()" function from the message sequence section on the inspector of every "END" node. Not sure exactly how that works, but it works.

Now I'm trying to make it so certain dialogue choices give + or - gold, faction points etc. How do I do this correctly?

I tried putting in multiple sendMessage lines separated by semicolons, but that doesn't seem to work.

Thank you!

Re: Executing multiple functions after a dialogue choice is made

Posted: Fri Jan 28, 2022 8:35 am
by Tony Li
Hi,

You can put multiple commands -- even multiple SendMessage() commands -- in a node's Sequence field, such as:

Code: Select all

SendMessage(CharacterLeave, , speaker);  // Call CharacterLeave() on the speaker.
SendMessage(Footsteps, , speaker);  // Call Footsteps() on the speaker.
LiveCamera(Wide, speaker, 2);  // Do a wide camera follow on the speaker.
However, SendMessage can only call C# methods that have no parameters or a single string parameter. If you have a C# method ModifyGold(int amount), then I recommend registering it with Lua (tutorial) and calling it in the node's Script field. Alternatively, you can write a custom sequencer command if you want to keep everything in the Sequence field, but I prefer to use the Sequence field for things the player directly experiences (such as animation, audio, and camerawork) and the Script field for data handling (such as incrementing gold and faction values).

Re: Executing multiple functions after a dialogue choice is made

Posted: Fri Jan 28, 2022 10:02 pm
by sunwooz
Thank you for the quick reply!

This is a lot simpler than I thought it would be.

You're helping us tell stories!

Re: Executing multiple functions after a dialogue choice is made

Posted: Fri Jan 28, 2022 10:39 pm
by Tony Li
Happy I could help! :-)