Call a function

Announcements, support questions, and discussion for the Dialogue System.
zenasprime
Posts: 14
Joined: Tue Apr 11, 2017 1:59 pm

Call a function

Post by zenasprime »

I'm looking for a way to call a function after a particular conversation node.

I see that there is an OnExecute event on the nodes but that these nodes do not accept any component objects from within the scene.

What I wanted to to was call a function that would load a new scene when that node was executed.

Is this possible or is there another way I should be calling functions as the result of a player choice in the dialogue?
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: Call a function

Post by Tony Li »

Hi,

There are two ways to call functions:

1. You can write a sequencer command and put it in the node's Sequence field. (Instructions) There's already a LoadLevel() sequencer command, BTW.

2. Or, register a function with Lua. (Instructions) There's a template for that, too, in the Scripts/Templates folder. Lua is usually used for data stuff, like checking the player's stats, while sequencer commands are used for user experience stuff, like controlling the camera and animation. But you can mix and match as you prefer.
zenasprime
Posts: 14
Joined: Tue Apr 11, 2017 1:59 pm

Re: Call a function

Post by zenasprime »

This is exactly what I am looking for. I used the first method. I already have it working.

Are there any caveats I should be aware of?

Thanks Tony!

:D
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: Call a function

Post by Tony Li »

Just one. Unless you're using a continue button, a dialogue entry's subtitle will appear onscreen for the duration of its sequence. The duration of a sequence is as long as its longest sequencer command. In your custom sequencer command, if you call Stop() inside the Start() method the command's duration will only be 1 frame. You may also need to add a "Delay({{end}})" sequencer command to give the sequence an appropriate duration.

For example, say you have a sequencer command "SpawnBoss()" that runs immediately. If your dialogue entry looks like this:
  • Dialogue Text: "I challenge you!"
  • Sequence: SpawnBoss()
Then the subtitle "I challenge you!" will only appear for 1 frame. Instead, you may want to change the Sequence to:
  • Dialogue Text: "I challenge you!"
  • Sequence: SpawnBoss(); Delay({{end}})
or even:
  • Dialogue Text: "I challenge you!"
  • Sequence: SpawnBoss()@{{end}}
To make the duration long enough for the player to read the Dialogue Text.
chud575
Posts: 50
Joined: Thu May 11, 2017 10:57 am

Re: Call a function

Post by chud575 »

Hey Tony,

I have a similar problem, can't seem to work it out.
I want to zoom my camera in (not an issue) when a convo starts, and go back to the original location when the conversation ends, but if I try:

Code: Select all

Camera(original,speaker,3)@{{end}};
it still ends up just snapping back. How can I accomplish this?
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: Call a function

Post by Tony Li »

Hi @chud575! Is there a typo? Does the Dialogue System log any warnings in the Console window? Have you assigned a separate sequencer camera to the Dialogue Manager's Camera Settings > Sequencer Camera, or are you just letting the conversation use the MainCamera?
chud575
Posts: 50
Joined: Thu May 11, 2017 10:57 am

Re: Call a function

Post by chud575 »

Tony Li wrote:Hi @chud575! Is there a typo? Does the Dialogue System log any warnings in the Console window? Have you assigned a separate sequencer camera to the Dialogue Manager's Camera Settings > Sequencer Camera, or are you just letting the conversation use the MainCamera?
Hi Tony!

Okay so - I was using the regular main camera. The issue (and maybe this post belongs here: viewtopic.php?f=3&t=942&p=4979&hilit=se ... nEnd#p4979)

I'm having is that I want the camera to always tween back to the original starting point after the conversation is over.
If I understand correctly, {{end}} is actually a float value, set in the manager, its not actually the "end" of the sequence or convo, right?

when I use a separate camera (EDIT: Or the main camera), it does tween back, but not when the conversation is over, but rather when the dialogue has completed it's typewriter process
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: Call a function

Post by Tony Li »

chud575 wrote:If I understand correctly, {{end}} is actually a float value, set in the manager, its not actually the "end" of the sequence or convo, right?
That's correct. It's equal to the higher value of:
  • Subtitle Settings > Min Subtitle Seconds, or
  • (length of Dialogue Text) / Subtitle Chars Per Sec
As soon as the conversation ends, the Dialogue System relinquishes control of the camera and immediately snaps it back to the original starting point.

Can you use the Camera(original,,3) sequencer command in the last node of your conversation? (The 'speaker' part isn't needed; if the camera angle uses the keyword 'original', it doesn't even look at the second argument.) If you're using a continue button mode, you can add an extra, blank node at the end and put the Camera() command on it.

If you need the camera movement to run after the conversation ends (rather than in the last node), you'll have to handle that in a separate script. Off the top of my head, here's one approach:

1. Write a custom sequencer command that simply records the current position of the MainCamera. Use this in the last node.

2. Add to the player or Dialogue Manager a script that has OnConversationStart and OnConversationEnd methods. In OnConversationStart, record the MainCamera's original position. In OnConversationEnd, tween from the position recorded by the sequencer command to the original position. If the script is on the player, it will only run for conversations involving the player. If the script is on the Dialogue Manager, it will run for all conversations.
chud575
Posts: 50
Joined: Thu May 11, 2017 10:57 am

Re: Call a function

Post by chud575 »

Tony Li wrote:Can you use the Camera(original,,3) sequencer command in the last node of your conversation? (The 'speaker' part isn't needed; if the camera angle uses the keyword 'original', it doesn't even look at the second argument.) If you're using a continue button mode, you can add an extra, blank node at the end and put the Camera() command on it.
Okay, so that works, I had tried that before actually, but I get a blank dialogue panel. How do I make it not appear?
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: Call a function

Post by Tony Li »

chud575 wrote:Okay, so that works, I had tried that before actually, but I get a blank dialogue panel. How do I make it not appear?
If your UI has a visible Dialogue Panel (and not just visible child subtitle panels and response menu panel), you'll have to deactivate it manually:

Code: Select all

SetActive(Dialogue Panel,false);
Camera(original,,3)
Don't worry about reactivating it. The Dialogue System will automatically reactivate it in the next conversation.
Post Reply