First a little background:
1. The timer events created by the (live:) macro interfer with the end-user's ability to interact with the page so it is generally recommend to have as few of these timers active at any one time, preferably only one. In your example you have two such (live:) macro timers with the same delay period active at the same time, which means you could easily combine the contents of the associated hooks of those two (live:) macros together.
2. Using a named hook combined with the (replace:) macro is an ideal way to update a known area of the page.
3. Once you have finished with your (live:) timer you should use a (stop:) macro to end it as soon as possible, unless the final iteration of that timer results in a Passage Transition (movement to another passage)
The following solution uses two named hooks (named dempsey and nikolai) to act as targets of the (replace:) macros being used to update the two people's dialogue, it uses a single (live:) plus a counter variable combined with an (if:) / (else-if) structure to control both the timing and what is shown, and it uses a (stop:) macro to stop the timer when the last line of the discussion is to be spoken.
{
|dempsey>[]
|nikolai>[]
}
{
(set: $timer1 to 0)
(live: 1s)[
(set: $timer1 to it + 1)
(if: $timer1 is 1)[
(replace: ?dempsey)[Hi Nikolai, how are you ?]
]
(else-if: $timer1 is 5)[
(replace: ?dempsey)[]
(replace: ?nikolai)[Good since last time, and you ?]
]
(else-if: $timer1 is 9)[
<!-- This is the last line of the discussion, stop the timer. -->
(stop:)
(replace: ?nikolai)[]
(replace: ?dempsey)[last line of the discussion]
]
]
}
Because the above example is using named hooks instead of ID'ed div elements to contain the individuals dialogue the CSS selectors within your project's Story Stylesheet are will need to be changed to target the named hooks instead.
tw-hook[name="dempsey"] {
position: fixed;
top: 0em;
left: 10em;
}
tw-hook[name="nikolai"] {
position: fixed;
top: 0em;
right: 10em;
}
note: Both your and my implementations currently have each line of the discussion spoken every 4 seconds after the first line has been spoken, this means that currently 3 iterations of the timer out of every 4 is wasted doing nothing but updating a counter variable.
If you are planning on continuing this pattern of the characters only speaking every 4 seconds then I suggest changing the main (live:) macro so that it's delay is 4s instead of 1s, you will also need to adjust the conditions of the (if:)/(else-if:) macros to compensate.
The replacement timer related code would look like the following, you will notice it uses two (live;) timers to control the timing difference between displaying the first line and the others, and that only one timer is active at any time.
{
(set: $timer1 to 0)
(live: 1s)[
(set: $timer1 to it + 1)
(replace: ?dempsey)[Hi Nikolai, how are you ?]
(stop:)
(live: 4s)[
(set: $timer1 to it + 1)
(if: $timer1 is 2)[
(replace: ?dempsey)[]
(replace: ?nikolai)[Good since last time, and you ?]
]
(else-if: $timer1 is 3)[
<!-- This is the last line of the discussion, stop the timer. -->
(stop:)
(replace: ?nikolai)[]
(replace: ?dempsey)[last line of the discussion]
]
]
]
}