Random no repeat conversations

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Intervention
Posts: 5
Joined: Fri Mar 09, 2018 3:38 pm

Random no repeat conversations

Post by Intervention »

Hi,

I am currently trying to make a scenario whereby the user gets random no repeat conversations and would like to ask if it is possible to random between conversations that have not been displayed before? Managed to get the no repeat part with simstatus, thanks.
User avatar
Tony Li
Posts: 21069
Joined: Thu Jul 18, 2013 1:27 pm

Re: Random no repeat conversations

Post by Tony Li »

Hi,

You can use a randomized Dialogue System variable. Here's an example that uses a small script:

RandomConversationsNoRepeat_2018-05-03.unitypackage

It's possible to do this with less scripting, but this little script makes the whole solution more compact. The script stores a random list of conversation numbers (from 1 to numConversations) in a Lua array named "convNum". It also sets a Lua variable "convIndex" to be the index of the first element in convNum.

The example scene has a "Start Conversation" button that starts a "hub" conversation titled "Starting Conversation". This links to the first node in three conversations (Conv1, Conv2, and Conv3):

Image

In those conversations, the first node requires that convNum[convIndex] is equal to a specific number (e.g., 1, 2, or 3). If so, it allows that conversation to play, and it increments convIndex:

Image

Here's the script, which is also included in the example scene:

RandomConversations.cs
Spoiler

Code: Select all

using UnityEngine;
using System.Linq;
using System.Collections.Generic;
using PixelCrushers.DialogueSystem;

public class RandomConversations : MonoBehaviour
{

    public int numConversations;

    private void Start()
    {
        // Initialize the conversationNumbers list:
        var orderedList = new List<int>();
        for (int i = 0; i < numConversations; i++)
        {
            orderedList.Add(i + 1);
        }

        // Put it into Lua as an array named "convNum[]":
        var luaCode = "convNum = {";
        foreach (var convNum in orderedList.OrderBy(x => Random.value))
        {
            luaCode += convNum + ",";
        }
        luaCode += "}";
        Lua.Run(luaCode);

        // And set the index position to the first element of the array:
        Lua.Run("convIndex = 1", true);
    }

}
Intervention
Posts: 5
Joined: Fri Mar 09, 2018 3:38 pm

Re: Random no repeat conversations

Post by Intervention »

Hi,

Thanks a lot!
User avatar
Tony Li
Posts: 21069
Joined: Thu Jul 18, 2013 1:27 pm

Re: Random no repeat conversations

Post by Tony Li »

Happy to help!
Post Reply