Executing multiple functions after a dialogue choice is made

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
sunwooz
Posts: 8
Joined: Thu Jan 27, 2022 10:54 pm

Executing multiple functions after a dialogue choice is made

Post 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!
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Executing multiple functions after a dialogue choice is made

Post 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).
sunwooz
Posts: 8
Joined: Thu Jan 27, 2022 10:54 pm

Re: Executing multiple functions after a dialogue choice is made

Post 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!
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Executing multiple functions after a dialogue choice is made

Post by Tony Li »

Happy I could help! :-)
Post Reply