Variables and Conditional Feedback

In my Twine scenario on stakeholder writing feedback, I show conditional feedback messages at the end based on the choices made. I do this by scoring the decisions and adding to a total score each time. At the end, I check the score and show a feedback message based on the range. I’ll explain step by step how I used scoring and feedback in Twine.

Try the scenario

You’ve seen this scenario before, but you may want to try it again below. If you try the scenario multiple times with different choices, you’ll see one of three different conditional feedback messages.

Good, OK, and bad choices

Twine scenario with passages tagged green, yellow, and red. These choices are scored to determine which conditional feedback message is displayed at the end.

This is a fairly simple scenario. Each decision has 3 choices: good, OK, or bad. Each passage is tagged accordingly. In Harlowe, you can color code each tag. I find that this helps me keep everything straight, so it’s worth time time to set it up before working on the variables.

Change the tag "good" to the color green

Set score variable default

In the first passage, I set the score to 0. That’s my default value. It’s important to reset this score at the beginning to allow users to replay the scenario.

In Harlowe (the default Twine story format), variables have a $ at the beginning. The code to create the variable $score and set it to 0 is:

(set: $score to 0)

Add scores for each choice

In this scenario, I will assign points for each choice aligned with the tags I already set.

  • Good = 3
  • OK = 2
  • Bad = 1

However, I can’t just set the variable to that score. If I did that, then the score would be reset after each choice. Instead, I need to add to the score.

In Harlowe, you add to a score by setting the score to itself plus a number. You can use the Harlowe toolbar and variables options to help you generate the correct code. This is can be helpful, especially when you’re first learning how to work with variables.

  1. Click the (Macro:) button.
  2. Select Value.
  3. Type the name of the variable (in this example, score).
  4. Change Value: to itself + value.
  5. In the it + ______ option, select number.
  6. Type the number to add to the score (in this example, 3).

At this point, your macro options should look like the image below.

Harlowe variable settings for the variable score, set to itself + value where the value is the number 3.

With the settings shown above, the resulting code is:

(set: $score to it + 3)

For my example, I copied and pasted that code to the remaining 8 passages that needed scores, changing the number as needed. If you prefer, you could go through the macro help each time.

Show conditional feedback messages

On the final passage, I have three different feedback messages.

  • “Good” if the score is >= 8.
  • “Not bad” if the score is 5-7.
  • “Bad” if the score is less than 5.

Once again, I used Harlowe’s built-in tools to create the If statement (although I had to do a little tweaking). Harlowe has a number of conditions for If statements. In this case, I want to show text if the variable $score is greater than 8. Click Macro: > If to add a conditional statement.

If function options in Harlowe for setting conditional feedback

This generates this code. The text between the brackets is called a “hook.” That’s where you put your feedback message.

(if:$score > 8)[Your Text Here]

The one problem with this is that the default choices only allow greater than or less than, not greater than or equal to. I manually edited the code to add the = and my feedback message.

(if:$score >= 8)[''Good job''
You did a good job advocating for your audience and using solid instructional writing techniques. Addressing learners directly, using a conversational tone, and aiming for plain language all help learners. Helping stakeholders see the benefits of better design will ultimately give them better results.]

For the next two score ranges, I set similar conditions. Make sure to check the “Also, only if the previous (if:), (else-if:) or (unless:) hook’s condition wasn’t fulfilled” option.

Full conditional feedback code

You can see the entire final feedback code below. The curly brackets {} around the feedback collapse the whitespace (otherwise the spacing looks weird when you publish the scenario).

{(if:$score >= 8)[''Good job''
You did a good job advocating for your audience and using solid instructional writing techniques. Addressing learners directly, using a conversational tone, and aiming for plain language all help learners. Helping stakeholders see the benefits of better design will ultimately give them better results.]

(else-if:$score >= 5)[''Not bad''
You pushed back on some of the stakeholder feedback, but you could have done more to educate your stakeholder about good instructional design. When stakeholders ask for changes that will make the course less effective, you can and should advocate for your learners.]

(else-if:$score < 5)[''Be brave!''
When stakeholders ask for changes, it's easy to say yes to everything. However, it's our responsibility as professionals to be more than just order takers. Be brave! You can educate stakeholders about the rationale behind your design decisions rather than accepting every suggestion. You'll create more effective solutions and provide better results if you advocate for the learners.]}