0 votes
by (150 points)

I have a passage in my game that deals with death. When you get to the death screen I have some random text telling how the player died. Some of those texts have parts that are delayed with a (live:) for various amounts of seconds. After 5 seconds I give the player the option to start over at the beginning of the game.

I had it working before adding the delayed text, but now I get errors each time I try to leave the passage. What causes this error?

Here is my code:

{
(set: $runOnce to 0)
(set: $death1 to "Your vision turns black, and some white text appears before you... (live: 2s)[GAME OVER<br/>](live: 3s)[Was all of this just a game?]")
(set: $death2 to "Your vision turns gray, as your lifeless body fumbles away. (live: 2s)[WASTED<br/>](live: 3s)[Wait, ](live: 4s)[did I just play GTA?]")
(set: $death3 to "You accidently clicked on a browser ad saying 'DIE FOR FREE!'")
(set: $death4 to "I like trains.(live: 2s)[<br/>Wait, what?](live: 3s)[<br/>*Chooo, chooo*](live: 4s)[<br/>Oh god, no!]")
(set: $death5 to "You dieded.")
(set: $funWaysToDie to (either: $death1, $death2, $death3, $death4, $death5))
}''Death''

(print: $funWaysToDie)

(live: 5s)[[[Try again?|Starting Area]]]

 

1 Answer

0 votes
by (159k points)
selected by
 
Best answer

Each time you use the (live:) macro within your TwineScript a new web-browser timer is created and started, and these timers will keep taking control (each time the related delay is pasted) of the page and executing the TwineScript within their associated hooks until one of three things occur.

1. The (stop:) macro is called from within the associated hook of the specific (live:) macro.

2. A Passage Transition occurs. (Story moves from one Passage to another, may be same passage.)

3. The HTML page is either refreshed in the web-browser or closed.

warning: The Reader's ability to interact with the page (eg. select links, etc...) is interrupted while the TwineScript associated with a timer is being executed, this is why we generally advise not having more that a single (live:) macro active within the current Passage being shown.

In your example you have between one and four timers active simultaneously depending on which random 'death' message is shown, and in the case where more than one of those timer's delay periods overlap the related timers will be competing for control of the page.

The following is one possible example of how to implement the functionality you want using a single (live:) macro combined with a named hook and the (append:) macro.

|message>[]
{
	(set: _roll to (random: 1, 5))
	(if: _roll is 1)[
		(set: $death to (a: "GAME OVER", "<br>Was all of this just a game?", ""))
		(append: ?message)[Your vision turns black, and some white text appears before you... ]
	]
	(else-if: _roll is 2)[
		(set: $death to (a: "WASTED", "<br>Wait, ", "did I just play GTA?"))
		(append: ?message)[Your vision turns gray, as your lifeless body fumbles away. ]
	]
	(else-if: _roll is 3)[
		(set: $death to (a: "", "", ""))
		(append: ?message)[You accidently clicked on a browser ad saying 'DIE FOR FREE!']
	]
	(else-if: _roll is 4)[
		(set: $death to (a: "<br>Wait, what?", "<br>*Chooo, chooo*", "<br>Oh god, no!"))
		(append: ?message)[I like trains.]
	]
	(else-if: _roll is 5)[
		(set: $death to (a: "", "", ""))
		(append: ?message)[You accidently clicked on a browser ad saying 'DIE FOR FREE!']
	]

	(set: $count to 0)
	(live: 1s)[
		(set: $count to it + 1)
		(unless: $count is 1 or $count is 5)[
			(set: _message to $death's ($count - 1))
			(unless: _message is "")[
				(append: ?message)[_message]
			]
		]
		(if: $count is 5)[
			(stop:)
			(append: ?message)[<br><br>[[Try again?|Starting Area]] ]
		]
	]
}

 

...