Creating Timed Response and Countdown Timer in Twine

This tutorial demonstrates how to make a timed response and countdown timer in the Harlowe 3.2.2 story format of Twine.

## Timed Response

### What is a timed response?

A timed response is when players are given a limited amount of time to make decisions. If the choice is not made in time, the game could progress to a different passage that is not part of the choices given. There can also be hidden consequences that can be saved in a variable and affect players later in the game if choice is not made in time. Timed responses can simulate the situation of a person getting cut off before they can speak during a conversation.

### Creating a timed response with the (live:) macro

#### What is the (live:) macro?

The (live:) macro is a changer, which means they only work when attached to a hook. The changer then modifies the hook. The (live:) macro is a changer that repeatedly replaces the code in the hook every set number of millisecond.

The following is the default form of the (live:) macro:

`(live: [Number]) -> Changer`

The default unit for [Number] is in milliseconds unless specified. The macro should be followed by a hook of some kind. For a timed response effect, we would use the command (go-to:). The (go-to:) command takes in a string, so it should be written in the format of (go-to: "Passage Name"). Note that the command must be placed in a hook [ ] or the command would immediately run and take you to the passage you used the (go-to:) command on. This will be demonstrated in the application example section.

#### Application example

Here is a basic application of the **(live:) macro:**

```
Beep!Beep!Beep!Beep!
[[Hit snooze->Fall asleep]]
[[Wake up->Wake up]]

(live: 3s)[(go-to: "Fall asleep")]

```

The passage simulates an event where an alarm clock is ringing in the morning. In this case, players are given 2 choices, **Hit snooze** or **Wake up**, which links to the passages **"Fall asleep"** and **"Wake up"** respectively. However, if players do not make a choice within 3 seconds they will be automatically sent to the **“Fall asleep”** passage.

The following is a demonstration of what happens when a command is not placed inside a hook:

```
Beep!Beep!Beep!Beep!
[[Hit snooze->Fall asleep]]
[[Wake up->Wake up]]

(live: 3s)(go-to: "Fall asleep")

```

Running the game takes you straight to the "Fall asleep" passage without encountering the "Waking up" passage. This is not what we want. We want to achieve the effect where at the "Waking up" passage we are given 3 seconds to make choices. If a choice is not made by that time, *then* we get sent directly to the "Fall asleep" passage. Therefore it is important to remember that commands and links must be placed in hooks [].

## Countdown Timer

A countdown timer can be displayed in the form of text for the players to see. This effect can be used as a way to indicate the passing of time to a player.

### How to implement a countdown timer?

A countdown timer can be created using variables and the (live:) changer.

#### Application example

Here is an application example of the countdown timer:

```
(set: $timer to 10)

(live: 1s)[
	You have $timer seconds left.
	(set: $timer to it -1)
    (if: $timer is 0)[
	(go-to: "End")
	]
]

```

‎

A variable $timer is set to a number value of 100. A change is made by the (live:) changer every 1 second. It is then displayed to player in text that they have $timer seconds left. The hook attached to the changer calls a (set:) command, which it decreases the $timer variable by 1. So together the variable decreases by 1 as every 1 second passes, creating the countdown effect. When $timer eventually reaches a value of 0, players will be sent to a passage called "end".

## Conclusion

There are many possible effects that can be achieved using the (live:) macro. Time response and countdown are only two examples that can act as a base for more advanced effects. They can be paired with other mechanics and are great for inducing a sense of urgency in players.

Note: If you find an effect made by another twine game creators interesting, you can download the game file and look at how it was made in twine. It is a great way to learn how to implement specific effects and can be applied to your own game by making appropriate changes.

## References

1. https://twine2.neocities.org/#macro\_live
2. https://twine2.neocities.org/#macro\_go-to
3. https://twine2.neocities.org/#type\_changer
4. https://damonwakes.wordpress.com/2019/01/19/twine-for-beginners-timers-and-live-text/
5. https://twinery.org/forum/discussion/5508/countdown-timer-harlowe