[HOWTO] How To: Make Quiz Conversations
Posted: Mon Nov 04, 2019 7:53 am
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
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]:
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:
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.
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) )]"
- NPC: Dialogue Text: "What is [var=x] + [var=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.