[HOWTO] How To: Make Quiz Conversations

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Tony Li
Posts: 22161
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Make Quiz Conversations

Post by Tony Li »

This post contains miscellaneous tips for setting up quiz conversations:

Example Scene
Here is a simple example scene that demonstrates a few of the tips below: QuizExample_2019-11-04.unitypackage
  • The quiz buttons (Quiz 1 Button & Quiz 2 Button) start conversations. On the Dialogue Manager, a component named Set Active On Dialogue Event hides these buttons during conversations.
  • Quiz 1 generates random values for an X + Y question. It also generates another random number that determines how many responses to show, just for variety. This relies on Lua, but the actual Lua code is very simple. More info: Lua.
  • Quiz 2 is a text question. It uses a script on the Dialogue Manager named ShuffleResponses to shuffle the responses. It uses a special method OnConversationResponseMenu.

Score
Add a variable named "Score".

Add a "quest" to display the current value of Score. Set its State to active, and tick Trackable and Track On Start so the quest tracker HUD will show it. In the Description, include the Score variable using the special markup tag [var=varName]:
  • Description: Current Score: [var=Score]

Show Questions In Random Order
To show questions in a random order, use the RandomizeNextEntry() Lua function or sequencer command. Note: To add variety to the phrasing of questions, use the RandomElement() function.


Show Answers In Random Order
To present answers in random order, shuffle them in an OnConversationResponseMenu() method. The example has a script ShuffleResponses that does this.


Randomize Quest Content
To change the content of questions and answers at runtime, use variables. For example, your conversation could look something like this:
  • START: Script:

    Code: Select all

    Variable["x"] = math.random(10); 
    Variable["y"] = math.random(10); 
    Variable["sum"] = Variable["x"] + Variable["y"]
    • NPC: Dialogue Text: "What is [var=x] + [var=y]?"
      • PC: <correct response> Dialogue Text: "[var=sum]"
      • PC: <random incorrect> Dialogue Text: "[lua( Variable["sum"] + math.random(5) )]"
The START node sets the variables x to a random number [1,10], y to a random number [1,10], and sum to x+y.

The first PC response is the correct answer.

The second PC response is an incorrect answer that adds a random value [1,5] to the correct sum.


Short Answer Questions
Use the TextInput() sequencer command to read text input from the user. Use the Lua string.lower() function to convert it to lowercase if want to allow case-insensitive answers.
Post Reply