Run lua script on node exit

Announcements, support questions, and discussion for the Dialogue System.
hipsterdufus
Posts: 97
Joined: Thu Aug 12, 2021 6:39 pm

Run lua script on node exit

Post by hipsterdufus »

Hi, is there any way to run a lua script when a conversation node ends as opposed to when it's entered? I notice there some @{{end}} command for sequences. Do I have to use sequences instead?
User avatar
Tony Li
Posts: 22158
Joined: Thu Jul 18, 2013 1:27 pm

Re: Run lua script on node exit

Post by Tony Li »

Hi,

Yes, you have to use sequences. The Script field isn't timed; it runs as soon as the dialogue entry is used.

Tip: Use the 'required' keyword if you want to make sure your sequencer command runs even if the player skips ahead before the time that it's supposed to run.
hipsterdufus
Posts: 97
Joined: Thu Aug 12, 2021 6:39 pm

Re: Run lua script on node exit

Post by hipsterdufus »

Thanks. As a workaround, I can add an extra dialogue box that contains nothing but the script. The only problem is I am always using the continue button so it creates an extra click for the player. Is there a way to turn that off temporarily? Maybe that will be good enough for me. If not, I'll have to look into how to use sequences.
hipsterdufus
Posts: 97
Joined: Thu Aug 12, 2021 6:39 pm

Re: Run lua script on node exit

Post by hipsterdufus »

Sorry, I was able to use sequencer and it is functioning but I still have an issue - the @{{end}} seems to trigger as soon as the subtitle text is done displaying. I'd like to trigger the sequence command when the continue button is pressed (or when the dialogue node is exited). Is that possible?
User avatar
Tony Li
Posts: 22158
Joined: Thu Jul 18, 2013 1:27 pm

Re: Run lua script on node exit

Post by Tony Li »

hipsterdufus wrote: Mon Aug 23, 2021 3:50 pmAs a workaround, I can add an extra dialogue box that contains nothing but the script. The only problem is I am always using the continue button so it creates an extra click for the player. Is there a way to turn that off temporarily? Maybe that will be good enough for me. If not, I'll have to look into how to use sequences.
If you use this solution, set the Sequence field to: Continue()

This will simulate an immediate continue button click.
hipsterdufus wrote: Mon Aug 23, 2021 4:15 pm Sorry, I was able to use sequencer and it is functioning but I still have an issue - the @{{end}} seems to trigger as soon as the subtitle text is done displaying. I'd like to trigger the sequence command when the continue button is pressed (or when the dialogue node is exited). Is that possible?
Instead of telling it to wait for the {{end}} duration (which is based on text length), tell it to wait for a bogus message:

Code: Select all

required YourCommand()@Message(WaitForever)
hipsterdufus
Posts: 97
Joined: Thu Aug 12, 2021 6:39 pm

Re: Run lua script on node exit

Post by hipsterdufus »

Thanks, I got things working now using a sequence command that waits for a message that the dialog box was closed which comes from my game's code.

It seems like sequences are the same as lua commands but a little more powerful because of the messaging system.
User avatar
Tony Li
Posts: 22158
Joined: Thu Jul 18, 2013 1:27 pm

Re: Run lua script on node exit

Post by Tony Li »

They each have their strengths. Sequences are good for timing things; hence the name "sequence." Lua has a more powerful code syntax since it's a full programming language. I generally recommend sequences for things the player experiences -- such as camera shots, animation, etc. -- and Lua for data management -- variables, quest states, etc.
hipsterdufus
Posts: 97
Joined: Thu Aug 12, 2021 6:39 pm

Re: Run lua script on node exit

Post by hipsterdufus »

Is there any way to close the Dialogue UI, pause for a few seconds, then reopen the Dialogue UI and continue the conversation on the next node? That would be a good use case for sequences right? I'd like to put some pauses like that in some of the longer cutscene conversations. Otherwise the conversation flows a little too quickly. I could break the conversation up and start the conversation from specific nodes but it would be easier if I can just do it with a sequence. I guess I'd have to write my own sequence to close and open the Dialogue UI?
User avatar
Tony Li
Posts: 22158
Joined: Thu Jul 18, 2013 1:27 pm

Re: Run lua script on node exit

Post by Tony Li »

Hi,

Use the SetDialoguePanel() sequencer command.
hipsterdufus
Posts: 97
Joined: Thu Aug 12, 2021 6:39 pm

Re: Run lua script on node exit

Post by hipsterdufus »

Wow, works very nicely. Thanks.
Post Reply