Page 1 of 1

Random no repeat conversations

Posted: Thu May 03, 2018 11:25 am
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.

Re: Random no repeat conversations

Posted: Thu May 03, 2018 4:01 pm
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);
    }

}

Re: Random no repeat conversations

Posted: Fri May 04, 2018 8:51 am
by Intervention
Hi,

Thanks a lot!

Re: Random no repeat conversations

Posted: Fri May 04, 2018 9:22 am
by Tony Li
Happy to help!