Call a function
-
- Posts: 14
- Joined: Tue Apr 11, 2017 1:59 pm
Call a function
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?
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?
Re: Call a function
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.
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.
-
- Posts: 14
- Joined: Tue Apr 11, 2017 1:59 pm
Re: Call a function
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!
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
Are there any caveats I should be aware of?
Thanks Tony!
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
Re: Call a function
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:
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()
- Dialogue Text: "I challenge you!"
- Sequence: SpawnBoss(); Delay({{end}})
- Dialogue Text: "I challenge you!"
- Sequence: SpawnBoss()@{{end}}
Re: Call a function
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:
it still ends up just snapping back. How can I accomplish this?
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}};
Re: Call a function
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?
Re: Call a function
Hi Tony!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?
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
Re: Call a function
That's correct. It's equal to the higher value of: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?
- Subtitle Settings > Min Subtitle Seconds, or
- (length of Dialogue Text) / Subtitle Chars Per Sec
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.
Re: Call a function
Okay, so that works, I had tried that before actually, but I get a blank dialogue panel. How do I make it not appear?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.
Re: Call a function
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: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?
Code: Select all
SetActive(Dialogue Panel,false);
Camera(original,,3)