Hi all,
I'm currently working on implementing a quiz system in Unity using the Dialogue System. The quiz answers and questions are retrieved from a database which means I need to delay updating the conversation until after the data is retrieved.
The issue I'm running into is that after the delay, Lua.Run doesn't seem to function as intended. I've tried running Lua.Run with debug and and allowExceptions flagged as true, but this nothing displays in the console. It's as if running Lua.Run causes the entire Dialogue System to freeze and stop functioning. If anyone has any ideas as to how I might make the Lua function work, I would greatly appreciate it.
Thanks!
Make Lua.Run work after a Time.Delay
Re: Make Lua.Run work after a Time.Delay
Hi,
Lua runs on the main thread. If you're blocking it to wait for a server response, the program will pause until it gets the response. I recommend using a UnityWebRequest to retrieve the quiz answers and questions. You can make the conversation wait on a dialogue entry by using the WaitForMessage() sequencer command or even a custom sequencer command. (See Sequences.) For example, your conversation might look like:
It uses a custom sequencer command that might look something like:
Lua runs on the main thread. If you're blocking it to wait for a server response, the program will pause until it gets the response. I recommend using a UnityWebRequest to retrieve the quiz answers and questions. You can make the conversation wait on a dialogue entry by using the WaitForMessage() sequencer command or even a custom sequencer command. (See Sequences.) For example, your conversation might look like:
It uses a custom sequencer command that might look something like:
Code: Select all
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
namespace PixelCrushers.DialogueSystem.SequencerCommands
{
public class SequencerCommandDownloadQuiz : SequencerCommand
{
IEnumerator Start()
{
using (UnityWebRequest webRequest = UnityWebRequest.Get("YOUR URL"))
{
yield return webRequest.SendWebRequest();
if (webRequest.result == UnityWebRequest.Result.Success)
{
// Handle webRequest.downloadHandler.text
}
else
{
Debug.LogError("Error downloading quiz.");
}
Stop();
}
}
}
}