Page 1 of 1

No Repeats, Random Conversations

Posted: Sat Feb 26, 2022 2:25 pm
by mokiedokes
Hello. I'm working on a mobile game that is comprised of minimal graphics and 300+ conversations. Conversations are organized into several tiers that get unlocked. Some conversations are unlocked after other conversations are completed.

I do not want conversations to repeat until all conversations in all tiers have been completed. I am using Playmaker with Dialogue System and have used Playmaker to randomize the conversations that run.

My question is how to save the conversations that have been completed and to use that information to ensure that the next conversation is not one that has been run already. I would like this information to be stored even after the user closes the app.

I was wondering if I could use PlayerPrefs to store a very long string of all completed conversations and search that string before running a convo to see if it has been run before. But I wasn't sure if that was the most prudent way of solving this. Thanks!

Re: No Repeats, Random Conversations

Posted: Sat Feb 26, 2022 3:32 pm
by Tony Li
Hi,

If that's all you need to save, you could use PlayerPrefs.

Or you could use the Dialogue System's save system. It has an Auto Save Load component which is helpful for mobile games.

I recommend setting a Dialogue System variable whenever a conversation starts. Then you can check if all of the variables corresponding to a tier's conversations have been set. You don't have to predefine these variables in the Dialogue Editor. You can add them at runtime. For example, if this method is in a script on the Dialogue Manager, it will save a Boolean variable for each conversation:

Code: Select all

void OnConversationStart(Transform actor)
{
    DialogueLua.SetVariable("Played_" + DialogueManager.lastConversationID, true);
}
To check if a conversation has been played:

Code: Select all

bool HasConversationBeenPlayed(int conversationID)
{
    return DialogueLua.GetVariable("Played_" + conversationID).asBool;
}
If you're using the save system, the Dialogue System Saver component will save the variables. If you're just using PlayerPrefs, you can get the variables as a string using PersistentDataManager.GetSaveData(), and restore the variables using PersistentDataManager.ApplySaveData(string).

Re: No Repeats, Random Conversations

Posted: Mon Feb 28, 2022 8:02 pm
by mokiedokes
Thanks, Tony. I went with the defining the variables in the Dialogue System conversation because I don't really know how to code. I added a condition at the first text node of each conversation that tests if the conversation has been played. I am able to ensure that it does not run repeat conversations. I am using Playmaker to randomly generate the conversations, to start them, and to generate a new random conversation once each conversation ends. My Playmaker conversation randomizer needs a ConversationEnd event in order to trigger the next randomized conversation.

I put my conditional check to see if the conversation has been played on the first child node after the Start node (always spoken by the NPC). I have a second node attached to the start node that is just an <> [End] node with no text or anything. Like so:
Picture of my setup
Picture of my setup
Dialogue setup.png (10.8 KiB) Viewed 985 times
The problem I'm having is that when the randomizer pulls up a conversation that has already been played, it goes to the <>[End] node and sits there for a second or two before pulling the next conversation. If I randomly get a few conversations in a row that have already been played, it is much too long before a new conversation plays. This would be an exponentially worse problem as my database grows.

Thank you for your generous time and help.

Re: No Repeats, Random Conversations

Posted: Mon Feb 28, 2022 8:11 pm
by Tony Li
Hi,

You could set the "<> [END]" node's Sequence to:

Code: Select all

Continue()
This will make it end immediately.

Alternatively, in your PlayMaker FSM you could use a Get Variable action check the conversation's variable. If it has already been set, you can immediately check a different conversation's variable instead of running the already-done conversation.

Re: No Repeats, Random Conversations

Posted: Mon Feb 28, 2022 8:18 pm
by mokiedokes
Thank you, thank you. I tried using a Dialogue System Get Variable action in the Playmaker FSM, but for some reason the variables for each conversation were not appearing as options. Is that because I set the variable at the end of the conversation? I don't want to register the conversation as played until the user has fully completed it.

Re: No Repeats, Random Conversations

Posted: Mon Feb 28, 2022 8:35 pm
by Tony Li
Hi,

Put the variable name in a PlayMaker string variable. For example, say your FSM has 3 PlayMaker variables:
  • conversationID: (Int) The conversation's ID number.
  • conversationVar: (String) Will hold "Played_conversationID".
  • wasConversationPlayed: (Bool) Will hold the value of the "Played_conversationID" DS variable.
Then use these actions to get the value of the "Played_conversationID" DS variable:

playMakerRandomNonRepeatConvs.png
playMakerRandomNonRepeatConvs.png (17.86 KiB) Viewed 983 times

Re: No Repeats, Random Conversations

Posted: Tue Mar 01, 2022 8:03 pm
by mokiedokes
Thanks again! You've been wonderfully helpful - I hope they pay you well! :)

(Sorry for all the super beginner questions. We have an adult family member with autism whose special interest (i.e. obsession) is teddy bears and dreams of making a game where players get to have a friendship with a teddy bear from outer space. We're trying to help facilitate the programming so they can do the fun writing part.)

Re: No Repeats, Random Conversations

Posted: Tue Mar 01, 2022 9:24 pm
by Tony Li
Glad to help, and good luck with your game!