Page 1 of 1
Running Custom Method after Certain Dialogue Node
Posted: Sun Nov 17, 2019 4:15 am
by Mackerel_Sky
Hi,
I've fixed all of my previous issues and am continuing to convert my code over to the Dialogue System. I'm now looking at implementing a shopkeeper functionality that can call an existing OpenShop() method from the NPC game object after a certain dialogue node is spoken (e.g. my previous system would call a function after the NPC spoke something like ''Take a look at my shop!'). I've been browsing through the manual and am having a bit of trouble finding what I'm looking for.
Can you point me to which articles or features might be relevant to implementing this feature?
Thanks!
Re: Running Custom Method after Certain Dialogue Node
Posted: Sun Nov 17, 2019 7:59 am
by Tony Li
Hi,
You could write a
custom sequencer command (more info:
Cutscene Sequences)
But in this case it's easier to use the built-in SendMessage() sequencer command. The player response dialogue entry node could look something like this:
- Dialogue Text: "What do you have for sale?"
- Sequence: SendMessage(OpenShop,,listener)
This will call OpenShop() on the node's listener (i.e., the shopkeeper NPC). Note the 2 commas between OpenShop and listener. This tells SendMessage() that OpenShop() has no parameters.
If you want to open the shop on the NPC's line, it would be something like:
- Dialogue Text: "Take a look at my shop!"
- Sequence: SendMessage(OpenShop)
I omitted the second parameter (argument to OpenShop(), since there is none) and the third parameter since the default for the third parameter is the speaker (i.e., shopkeeper).
Re: Running Custom Method after Certain Dialogue Node
Posted: Mon Nov 18, 2019 5:00 am
by Mackerel_Sky
Hey Tony,
Thanks for the reply. That's kind of what I was looking for, except the sequence is triggered during the dialogue. Is there a way to fire it after the conversation ends?
Off the top of my head I can think of a work around, being that the sequence will 'ready' the shop to be triggered and I can do something with OnConversationEnd() maybe to check whether or not I should open the shop, but it seems a bit clunky and I'm not completely sure if it will work. Not sure if you could have anything better than that in mind.
Thanks!
Re: Running Custom Method after Certain Dialogue Node
Posted: Mon Nov 18, 2019 8:40 am
by Tony Li
Here are two options:
1a. If you use continue buttons, use a sequencer command like this:
Code: Select all
required SendMessage(OpenShop)@Message(WaitForever)
The "@Message(WaitForever)" part tells the command to wait until it receives a sequencer message "WaitForever". (This is an arbitrary string. There's nothing special about "WaitForever". I just chose something that will never actually be sent.) However, the "required" part guarantees that the command will run when the node ends, even if it's still waiting for the message.
1b. If you're not using continue buttons, use a sequencer command like this:
This tells the command to wait for a duration based on the length of the dialogue text and the timing settings in the Dialogue Manager's Subtitle Settings.
2. Or set a dialogue database variable in the node's Script field:
If you've defined openShop in the Dialogue Editor's Variables section, you can use the "..." button to set up the Script field without having to do any typing.
Then add a Dialogue System Trigger to the shopkeeper or Dialogue Manager. Set its trigger to OnConversationEnd. Set the Condition > Lua Conditions to:
And add 2 actions:
- Run Lua Code:
- OnExecute() Event: Activate the shop. (Alternatively, use a Play Sequence action with SendMessage(OpenShop).)
Re: Running Custom Method after Certain Dialogue Node
Posted: Tue Nov 19, 2019 7:17 am
by Mackerel_Sky
Thanks, the first solution worked like a charm. Sequences seem extremely powerful- I'll definitely do some more research down the line about them.
Re: Running Custom Method after Certain Dialogue Node
Posted: Tue Nov 19, 2019 8:22 am
by Tony Li
Sounds good. Glad to help!