> For the complete documentation index, see [llms.txt](https://sweetforest.gitbook.io/quizquestion/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sweetforest.gitbook.io/quizquestion/the-quiz-question-system/en.md).

# The Quiz Question System \[EN]

The Quiz Question System lets you create multiple-choice questions using XML. It can randomize questions and answers. Creators can also add custom events.

## Requirement

* Unity 2019.4.31f1 OR Unity 2022.3.22f1
* VRC SDK - BASE,WORLD 3.4.2+

#### Recommended

* VRC SDK  (The latest version)
* Unity 2022.3.22f1

## How to use 📚

### 1. Place Prefab&#x20;

<figure><img src="https://3016712078-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjXTOK2hodBGk44geD5s1%2Fuploads%2FXvRG8zS6ZVRISE66LQFw%2Fimage.png?alt=media&amp;token=70127161-f4fb-42fc-a696-51d617f75997" alt=""><figcaption><p><mark style="color:red;">Drag Prefab</mark> <br><mark style="color:red;">into scene</mark><br><mark style="color:blue;">&#x26;</mark><br><mark style="color:purple;">If Text Mesh Pro appears, Click Import.</mark></p></figcaption></figure>

### 2. Unpack Prefab & Quiz Question Manager

<figure><img src="https://3016712078-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjXTOK2hodBGk44geD5s1%2Fuploads%2FMTwfj5o8Vkn5F8UgZxMl%2Fimage.png?alt=media&amp;token=53c7ef5b-4f1a-4edc-883f-848da297e544" alt=""><figcaption><p><mark style="color:purple;">Right-Click</mark> on <strong>Object</strong> <br>1. <mark style="color:blue;">Prefab</mark> -> <strong>Unpack Completely</strong> <mark style="color:red;">(Important)</mark><br>2. <mark style="color:green;">Open Quiz Question Manager</mark></p></figcaption></figure>

### 3. Quiz Question Manager️

Click on Load Quiz Question From XML and select .xml file , and you’re done!

<figure><img src="https://3016712078-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjXTOK2hodBGk44geD5s1%2Fuploads%2FXDijndwuRM8QHH1QQoMK%2Fimage.png?alt=media&amp;token=4b7b37c1-ad7e-4791-80fc-a96d7d1e0f68" alt=""><figcaption></figcaption></figure>

## How to write xml 📝

### Example

In the `<quiz>` element, the `random` attribute means random questions. The `limit` attribute specifies the number of questions to answer. The `correct` attribute in `<choices>` means correct choice.

You don't need to add these attributes; the default values are:

* `random`: true
* `limit`: n number of questions
* `correct`: false

`If you want the limit to be`` `**`equal to the total number of questions`**`, set the value to`` `**`0`**`. If you set the limit higher than the number of available questions, the questions`` `**`will loop`**`.`

You can use rich text by formatting it as follows: `[...]___[/...]`.\
`[color=red]肉 (Meat)[/color]`

```xml
<quiz random="true" limit="0">
  <question>
    <text>[b][color=blue]猫は何を食べますか？[/color] (What do cats eat?)[/b]</text>
    <choices random="true">
      <choice>[color=red]肉 (Meat)[/color]</choice>
      <choice correct="true">[color=green]魚 (Fish)[/color]</choice>
      <choice>[color=blue]野菜 (Vegetables)[/color]</choice>
      <choice>[color=purple]果物 (Fruits)[/color]</choice>
    </choices>
  </question>
  <question>
    <text>[b][color=blue]猫は何色の目を持っていますか？[/color] (What color eyes do cats have?)[/b]</text>
    <choices>
      <choice>[color=blue]赤 (Red)[/color]</choice>
      <choice>[color=red]緑 (Green)[/color]</choice>
      <choice correct="true">[color=green]黄色 (Yellow)[/color]</choice>
      <choice>[color=purple]青 (Blue)[/color]</choice>
    </choices>
  </question>
  <question>
</quiz>
```

```xml
<quiz> 
 <question>
    <text>10 ÷ 2 はいくつですか？ (What is 10 ÷ 2?)</text>
    <choices>
      <choice>2</choice>
      <choice>3</choice>
      <choice correct="true">5</choice>
      <choice>6</choice>
      <choice>7</choice>
      <choice>8</choice>
      <choice>9</choice>
    </choices>
  </question>
  <question>
    <text>7 + 4 はいくつですか？ (What is 7 + 4?)</text>
    <choices>
      <choice>9</choice>
      <choice>10</choice>
      <choice>11</choice>
      <choice correct="true">11</choice>
      <choice>12</choice>
      <choice>13</choice>
      <choice>14</choice>
    </choices>
  </question>
</quiz>
```

### Rich Text

| `[br]`        | Creates a new line.                                                                |
| ------------- | ---------------------------------------------------------------------------------- |
| `[u]`         | Underlines the text.                                                               |
| `[i]`         | Makes the text italic.                                                             |
| `[color]`     | Changes the color of the text (using HEX or color names).                          |
| `[size]`      | Changes the size of the text (specifying a number or relative size).               |
| `<s>`         | Strikes through the text.                                                          |
| `[b]`         | Makes the text bold.                                                               |
| `and more...` | <https://docs.unity3d.com/Packages/com.unity.textmeshpro@4.0/manual/RichText.html> |

## Developer 💻

### Create Custom Trigger Event️

To create a UdonSharp (U#) script with an inheritance class `QuizEvent`, you can define a base class and then create a derived class that overrides a method.&#x20;

```csharp
public override void AfterUpdatedQuestionsUI(Quiz quiz){ }
public override void AfterClickAnswer(Quiz quiz,bool isCorrect){  }
public override void OnCompletedQuizQuestions(Quiz quiz,QuestionData questionData,bool hasPassed){ }
public override void OnStartQuizQuestions(Quiz quiz){  }
```

### Register To Quiz Triggers&#x20;

<figure><img src="https://3016712078-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjXTOK2hodBGk44geD5s1%2Fuploads%2FYAyd4e8IMCuMMljUhByE%2Fimage.png?alt=media&amp;token=ed3266d9-b89a-4673-8dee-2939364e0602" alt="" width="362"><figcaption><p>Right Click on Quiz GameObject in the scene</p></figcaption></figure>

To add a new trigger event script, click the '+' button to add an element, and then put the script into element.

#### Adjust Priority?

<figure><img src="https://3016712078-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjXTOK2hodBGk44geD5s1%2Fuploads%2FzcPww6I99fHmy9np6Zo6%2Fimage.png?alt=media&amp;token=c5f6fe4d-8974-4c5a-98d8-5a8678c9675c" alt=""><figcaption><p>Move the element, first in, first run</p></figcaption></figure>

#### Default Trigger Event Script

<table><thead><tr><th>Trigger Event</th><th>Information</th></tr></thead><tbody><tr><td><pre class="language-csharp"><code class="lang-csharp">VisibleObjectWhenResetOrStart
</code></pre></td><td>Show or hide a GameObject when the quiz starts.</td></tr><tr><td><pre class="language-csharp"><code class="lang-csharp">TeleportWhenCompleted
</code></pre></td><td>Teleport the player to a target location when they fail or pass.</td></tr><tr><td><pre class="language-csharp"><code class="lang-csharp">SensitiveAnswer
</code></pre></td><td>Automatically fail and end the quiz on an incorrect answer.</td></tr><tr><td><pre class="language-csharp"><code class="lang-csharp">PlayMeowWhenClickQuestion
</code></pre></td><td>Play a random-pitched meow sound when the answer is correct.</td></tr><tr><td><pre class="language-csharp"><code class="lang-csharp">QuizSoundEffect
</code></pre></td><td>Default sound effects for the quiz (fail, complete, next page).</td></tr><tr><td><pre class="language-csharp"><code class="lang-csharp">TimeOutQuiz
</code></pre></td><td>End the quiz and mark it as failed</td></tr></tbody></table>

### Example

```csharp
public class PlayMeowWhenClickQuestion : QuizEvent
{
    public QuizSoundFX Meow;
    public bool OnlyCorrect;
    public override void AfterClickAnswer(Quiz quiz,bool isCorrect){

        if(quiz.CurrentLimitFinishQuestion > 1) {
            
            if(OnlyCorrect) {
                if(isCorrect) {
                    Meow.playRandomPitch();
                }
            } else {
                Meow.playRandomPitch();
            }

        }

    }
    
}

```

### Utilities

#### QuizAudioFX

Add the QuizAudioFX script to an Audio Source GameObject. The script can play sound with customizable pitch, volume, or random pitch.

Other in `Sweet Forest/Quiz/Scripts/Events`

<table><thead><tr><th>Utilities Scripts</th><th>Information</th></tr></thead><tbody><tr><td><pre class="language-csharp"><code class="lang-csharp">InteractResetQuizObject
</code></pre></td><td>Interact to reset the quiz.</td></tr><tr><td><pre class="language-csharp"><code class="lang-csharp">ToggleObjectInteract
</code></pre></td><td>Toggle to show or hide a GameObject.</td></tr></tbody></table>

<table><thead><tr><th>Knowing Quiz Method</th><th>Information</th></tr></thead><tbody><tr><td><pre class="language-csharp"><code class="lang-csharp">GetScores()
</code></pre></td><td>Returns the number of correct answers.</td></tr><tr><td><pre class="language-csharp"><code class="lang-csharp">GetMaxScore()
</code></pre></td><td>Returns the maximum possible score.</td></tr><tr><td><pre class="language-csharp"><code class="lang-csharp">CurrentLimitFinishQuestion
</code></pre></td><td>Return the number of remaining questions to complete.</td></tr><tr><td><pre class="language-csharp"><code class="lang-csharp">ForceImmediatelyQuiz(bool makePass)
</code></pre></td><td>Forcibly ends the quiz.</td></tr><tr><td><pre class="language-csharp"><code class="lang-csharp">ForceImmediatelyPassQuizAndComplete()
</code></pre></td><td>Forces a pass for the quiz.</td></tr><tr><td><pre class="language-csharp"><code class="lang-csharp">GetCurrentQuestion()
</code></pre></td><td>Current Question Data.</td></tr><tr><td><pre class="language-csharp"><code class="lang-csharp">UpdateQuestionsUI()
</code></pre></td><td>Update UI.</td></tr><tr><td><pre class="language-csharp"><code class="lang-csharp">Reset()
</code></pre></td><td>Resets the quiz.</td></tr></tbody></table>

## Video Demo 📺

{% embed url="<https://www.youtube.com/watch?v=93M9JfQPc6c>" %}
