Refresh score in footer immediately when incremented

I have created a footer (a passage with the tag “footer”), which tells the score:

Score: $score out of 3

I would like to reward points to the player when they click on some (link-reveal: "...") words, which expand into paragraphs with more details.

I add (set: $score +=1) to increment the score, but the footer is not refreshed—of course. The new score appears when the player moves on to the next passage, because that’s when the footer passage gets re-run.

How can I refresh the footer so that it shows the score within the same passage?


Please specify version and format if asking for help, or apply optional tags above:
Twine Version: 2
Story Format: Harlowe 3.1

This is generally achieved by using a Named Hook to to identify an area of the page…

Score: |score>[$score] out of 3

…and a (replace:) macro to replace the current content of that area.

(link-reveal: "...")[More blah blah. (set: $score = it + 1)(replace: ?score)[$score]]

warning: If you review the Harlowe (set:) macro documentation you will notice that the story format doesn’t officially support the JavaScript += (increment) or the -= (decrement) operators. The documented method for incrementing a variable is…

(set: $vases to it + 1) or (set: $vases to $vases + 1)

…and the decrementing equivalents would be…

(set: $vases to it - 1) or (set: $vases to $vases - 1)
1 Like

Thanks so much @Greyelf, I’ll try this tonight!