Page 1 of 2
Make a custom LUA script run after the end of a conversation
Posted: Mon Jul 24, 2023 10:07 pm
by Shinos
Hi,
I have run into a fairly simple problem i think, i have a custom event system that i implemented, and i did also customLua command to do the raise of specific events within the dialogue entries, so i thought to do as one of the responses for an event call to start a new conversation when the current one ends , but i discovered that since the script is run a lil before the sequence ends, i get the warning "dialogue system: anoother conversation is already active", and if i allow to overwrite the convo even if it is already started, i lose the last sequence of the current event calling conversation.
So this is it i am trying to find either an alternative to easily start a new conversation at the end of an other, or to make a script run after the end of the dialogue entry.
Also it could be good to understand how to delay a little the start of this new conversation.
like what i want is "conversation 1 is running, it ends, after 4 seconds new conversation starts"
Re: Make a custom LUA script run after the end of a conversation
Posted: Tue Jul 25, 2023 8:54 am
by Tony Li
Hi,
If you want your code to know when a conversation ends, you can add a script to the Dialogue Manager or a conversation participant that has an
OnConversationEnd(Transform) method or hooks into the C# event DialogueManager.instance.conversationEnded, or use a
Dialogue System Events component. Example:
Code: Select all
void OnConversationEnd(Transform actor)
{
if (DialogueManager.lastConversationStarted == "Your First Conversation")
{
DialogueManager.StartConversation("Your Second Conversation");
}
}
You can also add a (second) Dialogue System Trigger to a participant and set its Trigger dropdown to OnConversationEnd. This Dialogue System Trigger will run its actions when a conversation involving the participant ends.
Re: Make a custom LUA script run after the end of a conversation
Posted: Tue Jul 25, 2023 10:48 am
by Shinos
Hi,
I was trying to avoid the OnConversationEnd because i would like to get a more "general" solution, because from what you suggested if i got it correctly i would need to do a check at every conversationend to see if the conversation i need ended, by checking it's name, and i don't like it really much for something as simple as this.
i don't know if this is effective at all but since what i need for now is just a simple workaround to get my script be called from the dialogue system after the last sentence in the conversation, what i thought to do was: to put a blank dialogue after the last sentence, and call the script in that dialogue, so that even if the dialogue gets overwritten, it actually does not cause any damage.
my only problem is that i don't know how to call the start of a new conversation from the sequence command, do i need to do a custom one? also i have seen that in the component trigger there is the option to replace a conversation, but i haven't found it anywhere else, cause i could also just trigger an event which does the start of a new conversation, but it need to be able to replace the current one, also the other issue is that the dialogue gets called immediately, but what i would need is to like wait a bit as i said before calling it, i tried using "delay" but it does not work, how do i effectively delay the start of a conversation after i trigger it.
Re: Make a custom LUA script run after the end of a conversation
Posted: Tue Jul 25, 2023 10:55 am
by Shinos
Tony Li wrote: ↑Tue Jul 25, 2023 8:54 am
Hi,
If you want your code to know when a conversation ends, you can add a script to the Dialogue Manager or a conversation participant that has an
OnConversationEnd(Transform) method or hooks into the C# event DialogueManager.instance.conversationEnded, or use a
Dialogue System Events component. Example:
Code: Select all
void OnConversationEnd(Transform actor)
{
if (DialogueManager.lastConversationStarted == "Your First Conversation")
{
DialogueManager.StartConversation("Your Second Conversation");
}
}
You can also add a (second) Dialogue System Trigger to a participant and set its Trigger dropdown to OnConversationEnd. This Dialogue System Trigger will run its actions when a conversation involving the participant ends.
What i initially did was this:
- 123.png (90.07 KiB) Viewed 950 times
now the event raise would trigger these responses:
- 123124.png (29.6 KiB) Viewed 950 times
as you can see one of em is the Start of a new conversation, but it gets blocked by the fact that it cannot replace the current one because when the RaiseProgressEvent() gets called, for the dialogue system the dialogue has not yet ended, this could be easily solved if only the script could be called after the dialogue line and not as soon as it gets to that node
Re: Make a custom LUA script run after the end of a conversation
Posted: Tue Jul 25, 2023 11:47 am
by Tony Li
Hi,
You can't do that because the Script runs within the context of the current conversation.
However, if you don't want to use any of my suggestions above, you could modify your RaiseProgressEvent() to wait one frame if it's at the end of the conversation. Something like:
Code: Select all
public void RaiseProgressEvent()
{
StartCoroutine(RaiseProgressEventCoroutine());
}
IEnumerator RaiseProgressEventCoroutine()
{
bool isAtEnd = !DialogueManager.currentConversationState.hasAnyResponses;
if (isAtEnd) yield return null; // Wait for conversation to close out.
DoMyEvents();
}
Re: Make a custom LUA script run after the end of a conversation
Posted: Tue Jul 25, 2023 12:11 pm
by Shinos
Thanks, i'll try this, to be honest i did not understand fully how to implement easily your first suggestion, that's why i was trying to avoid it, but maybe it could work, like what your process would be to make a conversation start by script at the end of a first one?
PS: i ran into a weird issue, whenever i try to start a conversation by script, like using DialogueManager.StartConversation("");
the conversation does not keep the custom display settings i override, like i put to a conversation to ALWAYS use continue button, but when i call it like this it just begin to go on automatically between the lines using the "never" default display settings in the dialogue manager .
Re: Make a custom LUA script run after the end of a conversation
Posted: Tue Jul 25, 2023 2:31 pm
by Tony Li
Where are the display settings overrides? On a character's GameObject or in the conversation's properties in the Dialogue Editor?
If it's on a character's GameObject, make sure to pass that character's transform to DialogueManager.StartConversation(). For example, if your NPC has an Override Display Settings component:
Code: Select all
DialogueManager.StartConversation("Title", player.transform, npc.transform);
Re: Make a custom LUA script run after the end of a conversation
Posted: Tue Jul 25, 2023 3:00 pm
by Shinos
Tony Li wrote: ↑Tue Jul 25, 2023 2:31 pm
Where are the display settings overrides? On a character's GameObject or in the conversation's properties in the Dialogue Editor?
If it's on a character's GameObject, make sure to pass that character's transform to DialogueManager.StartConversation(). For example, if your NPC has an Override Display Settings component:
Code: Select all
DialogueManager.StartConversation("Title", player.transform, npc.transform);
They are in the conversation properties
- 123123123.png (56.66 KiB) Viewed 926 times
Re: Make a custom LUA script run after the end of a conversation
Posted: Tue Jul 25, 2023 4:19 pm
by Tony Li
In that case they should take effect unless one of the participants has an Override Display Settings component, or if maybe the Dialogue Manager is pointing to a different copy of your dialogue database that doesn't override the properties.
Re: Make a custom LUA script run after the end of a conversation
Posted: Tue Jul 25, 2023 4:23 pm
by Shinos
Tony Li wrote: ↑Tue Jul 25, 2023 4:19 pm
In that case they should take effect unless one of the participants has an Override Display Settings component, or if maybe the Dialogue Manager is pointing to a different copy of your dialogue database that doesn't override the properties.
That's really weird, i also tried doing 2 new conversation from scratch, and this still happens, i don't know why
i'm just calling this method:
Code: Select all
public void StartConv(string a)
{
DialogueManager.StartConversation(a);
}
when the event is raised, and it works to switch the conversation, but it uses the settings in the default manager, in fact, if i set the default manager setting to be "Always" it goes on continue, but it does not listen the override setting, it's worth to say that in order to do this i activated simultaneous conversation to trigger the new convo in a blank sentence of the previous one, as i said earlier.