# Smartwords

The full explanation and reference to Smartwords is linked below but here we'll provide some examples and "how to" of things you might want to try.

{% content-ref url="<https://app.gitbook.com/s/sNKxYbIPgfYmCR9EJgAu/feature-documentation/designing-and-running/smartwords>" %}
[Smartwords](https://app.gitbook.com/s/sNKxYbIPgfYmCR9EJgAu/feature-documentation/designing-and-running/smartwords)
{% endcontent-ref %}

{% content-ref url="<https://app.gitbook.com/s/sNKxYbIPgfYmCR9EJgAu/feature-documentation/designing-and-running/smartwords/functions>" %}
[Functions](https://app.gitbook.com/s/sNKxYbIPgfYmCR9EJgAu/feature-documentation/designing-and-running/smartwords/functions)
{% endcontent-ref %}

## Smartwords - Quick Reference

`{score}`  prints the player's score

`{data.$$$}` (where $$$ is the index) prints a Smartword from the Smartwords Library

`|audience.response|` is the player's last answer

`|DATETIME(NOW())|` is the time now (see DATETIME formatting to see how to format)

`|audience.responses["exs.#####"]|` is the player's response to the question ##### Note this is **not** the step number but a unique identifier. See example below.&#x20;

## 🎓Examples

#### Arrange example

The Arrange question type will produce an audience.response in the format 1234 (for a four-option question) where the number represents the original option and sequence is the arrangement from the player. For example, if the player drags the bottom answer to the top to make it their highest priority then the audience.response will be 4123

In this example we have a Title and a Body dependent on the arrangement of the top TWO options. In order to index the smartword library we need to add (ie. concatenate)  the text "Title\_" with the first two numbers in the four-number sequence.

<div align="left"><figure><img src="https://3202416344-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkKsE69Z3PsghYNFs2oFd%2Fuploads%2Fr7KS48p7hYXa8cSmXyh9%2Fimage.png?alt=media&#x26;token=fc43a22b-d872-439c-b9e6-8fee30b67be3" alt=""><figcaption></figcaption></figure></div>

To accomplish this we need these smartwords/functions;

* audience.response to get the option sequence from the player's arrangement
* LEFT to take the first two digits
* CONCAT to add&#x20;
* |partition.custom\_data\[]| is the array containing the exercise smartword library

{% hint style="info" %}
`{data.Title_43}` is the same as `|partition.custom_data["Title_43"]|` but we can't mix {} with ||. And in this use case we need to use || in order to be able to use the functions&#x20;
{% endhint %}

This is how the final smartword is contructed

{% stepper %}
{% step %}

### Get the top two options

If the full arrangement is 4312 then to get "43" we use |LEFT(audience.response,2)| &#x20;
{% endstep %}

{% step %}

### Add Title or Body to form the Smartword Library index

|CONCAT("Title\_"LEFT(audience.response,2))|  will give us "Title\_43"&#x20;
{% endstep %}

{% step %}

### Look up the result in the Smartword Library

|partition.custom\_data\[CONCAT("Title\_"LEFT(audience.response,2))]|
{% endstep %}
{% endstepper %}

{% hint style="info" %}
Note the use of \[ ] which denotes an array (ie the library) while ( ) denotes a function.
{% endhint %}

The final content in the Editor looks like this:

<div align="left"><figure><img src="https://3202416344-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkKsE69Z3PsghYNFs2oFd%2Fuploads%2F6g5zwiBwFItv5fFw3VeN%2Fimage.png?alt=media&#x26;token=32689b38-87a8-43fc-9a7d-4889da144646" alt=""><figcaption></figcaption></figure></div>

The result for the player looks like this:

<div align="left"><figure><img src="https://3202416344-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkKsE69Z3PsghYNFs2oFd%2Fuploads%2FGnnTlD82Z5h4d2jemSyw%2Fimage.png?alt=media&#x26;token=604e624f-38e8-4805-b6be-e613e25baf5b" alt=""><figcaption></figcaption></figure></div>

#### MultiChoice example

You can see from the Smartword Library below that multichoice responses are represented by 1 when the option is selected and 0 when its not.

<div align="left"><figure><img src="https://3202416344-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkKsE69Z3PsghYNFs2oFd%2Fuploads%2FK5daS0d6tg0mPEk2Pq4S%2Fimage.png?alt=media&#x26;token=bb3f984e-2c98-4cce-9165-e949cdf281be" alt=""><figcaption></figcaption></figure></div>

Because we have an entry for every combination of a 4-option multichoice question it's very easy to index the value - as shown below.

<div align="left"><figure><img src="https://3202416344-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkKsE69Z3PsghYNFs2oFd%2Fuploads%2FNNAuWbkDnJlVJvFsNUgE%2Fimage.png?alt=media&#x26;token=330d83dc-42da-4e5c-b6c1-52b27e1d5491" alt=""><figcaption></figcaption></figure></div>

The result for the player looks like this

<div align="left"><figure><img src="https://3202416344-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkKsE69Z3PsghYNFs2oFd%2Fuploads%2FrpPtVdFMwsd7IDw9OIyq%2Fimage.png?alt=media&#x26;token=32390efa-d005-4671-8e30-dc4b5c12b006" alt=""><figcaption></figcaption></figure></div>

### 🎓Accessing question results

<figure><img src="https://3202416344-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkKsE69Z3PsghYNFs2oFd%2Fuploads%2FqshZ47FMK05Ku21eybU5%2Fimage.png?alt=media&#x26;token=c2fbc9fc-3d5c-4ef0-b1f6-ee07a4834086" alt=""><figcaption></figcaption></figure>

If you want to use the response immediately then you can use `|audience.response|`  - it's much easier! However in my example I allow the player to return to this step from other rows and then the audience.response won't be the opentext question. Hence the need to code the exact question.

You'll also have to use this approach if you want to reference the answer much later, for example giving a summary perhaps.

<div align="left"><figure><img src="https://3202416344-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkKsE69Z3PsghYNFs2oFd%2Fuploads%2FQTqQskqVhk7f10DZfS0v%2Fimage.png?alt=media&#x26;token=709b3758-93d3-4f8a-8cf7-a82e1d3f4ce6" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
Note the question index - "exs.#####" - must be in quotes.
{% endhint %}

#### How to find the unique question number

To find the question number requires some experimentation/prototyping.

{% stepper %}
{% step %}

### Make sure the data point is empty

<div align="left"><figure><img src="https://3202416344-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkKsE69Z3PsghYNFs2oFd%2Fuploads%2FoU2gs5PgXnw7ecFrkqVP%2Fimage.png?alt=media&#x26;token=863441ac-70e5-45bb-a097-25f7f6cad6d9" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

### Run the exercise and then Export the Colibri Report

<div align="left"><figure><img src="https://3202416344-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkKsE69Z3PsghYNFs2oFd%2Fuploads%2FYm7opMt4bPR93qISSQ8Z%2Fimage.png?alt=media&#x26;token=da4971ca-c568-4484-a1a8-ab3f123f42b6" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

### Open the Report and find the Answer

The column header will have the question index you need.

<div align="left"><figure><img src="https://3202416344-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkKsE69Z3PsghYNFs2oFd%2Fuploads%2FjIf1n9KpMrWbfdTQQ3lj%2Fimage.png?alt=media&#x26;token=484e205f-8270-4e58-9b02-3a079f5d600f" alt=""><figcaption></figcaption></figure></div>
{% endstep %}
{% endstepper %}

### 🎓DATETIME example

<div align="left"><figure><img src="https://3202416344-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkKsE69Z3PsghYNFs2oFd%2Fuploads%2FLu8h6DPXH1A5HP6OeTKW%2Fimage.png?alt=media&#x26;token=64d1adc0-8099-422d-8582-f19aede9ed92" alt=""><figcaption></figcaption></figure></div>

To make the above email look authentic it needed to be dated and timestamped with the time the player invoked the publication and for the warning to be abut an event three days from that time.

This is what the content looks like for the designer

<div align="left"><figure><img src="https://3202416344-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkKsE69Z3PsghYNFs2oFd%2Fuploads%2Fk9LBlQ7jKrH1R19YWHhk%2Fimage.png?alt=media&#x26;token=a9d2b9b3-e33a-4e3e-a1c2-867384103b57" alt=""><figcaption></figcaption></figure></div>

The function NOW() give us the date & time right *now*.

The DATETIME function formats the NOW() result into a format suitable for our purposes.

Note that you can add and subtract time as is shown

* |DATETIME(NOW()**-"01:25:00",**"HH:mm")|  is 1hr 25mins before now
* |DATETIME(NOW()**+"03:00:00:00"**,"DD MMM YYYY")|  is three days from now

### Debugging Smartwords

If in doubt, add your smartword or function to the content body and see what result you get.

{% hint style="info" %}
To see an example of **smartwords in action**, visit the page below:
{% endhint %}

{% content-ref url="../examples/mechanics-examples" %}
[mechanics-examples](https://helpdocs.conducttr.com/colibri/examples/mechanics-examples)
{% endcontent-ref %}
