0 votes
by (310 points)

Hey everyone! I found myself at a dead end recently when I was trying to do the following: print some text "It's too bright in here." (that blinks using the text style changer); then print some text that also blinks and when clicked, disappears and changes the text "it's too bright in here." with "That's better.", that does not have any text style effect. 

Here is what I have so far:

|blinking>[(live: 5s)[(stop:)(t8n:"dissolve")+(colour: black)+(text-style: "blink")[It's too bright in here.]]]

(live:  8s)[(t8n:"dissolve")+(colour: black)+(text-style: "none")[(stop:)You should (link: "turn off the light")[(replace: ?blinking)[(text-style: "none")That's better.]]]

This are some things I can assume, with my limited knowledge:

  1.  I have stopped the second timer in a bad place that is awkward.
  2. There is a problem with how I am introducing the (replace:) macro at the wrong time, or without proper notation.
  3. I have wrongly introduced the link and any non-text elements.
  4. I have also probably wrongly added the (text-style: "none") macro.

 

Thanks a bunch for any help. :)

1 Answer

+1 vote
by (159k points)
selected by
 
Best answer

The following uses a hook named output as the target area of all the displayed text, it uses Collapsing whitespace markup and br elements to control the layout of the displayed text while still allowing formatting of the passage content.

|output>[]

|workarea>[{

	(live: 5s)[
		(stop:)
		(append: ?output)[
			(t8n: "dissolve") + (colour: black) + (text-style: "blink")[It's too bright in here.]
		]
	]

	(live:  8s)[
		(stop:)
		(append: ?output)[
			<br><br>
			(t8n: "dissolve") + (colour: black) + (text-style: "none")[
				You should 
				(link: "turn off the light")[
					(replace: ?output)[That's better.]
				]
			]
		]
	]
}]

warning: Timers are an expensive proces, which can interfere with the end-user's ability to interact with the page while the timer executies it's associated hook. So we generally advise having as few of them as possible active at the same time. eg. one is a good number.

you will notice that I placed the processing logic part of the about example within it's own hook named workarea, this allows me to use CSS (in the Story Stylesheet area) to supress all unwanted visual output that code may generate.

tw-hook[name="workarea"] {
	display: none;
}

 

by (310 points)

Okay, so this solved the problem, but I had some issues when I wanted to further progress. If I wanted more than one "thing" to happen when I click the link "turn off the light", for example for the background colour and text colour to change, how would I achieve this? This is what I've got, but it fails to change anything but doesn't show any errors either.

|output>[]

|workarea>[{

	(live: 5s)[
		(stop:)
		(append: ?output)[
			(t8n: "dissolve") + (colour: black) + (text-style: "blink")[It's too bright in here.]
		]
	]

	(live:  8s)[
		(stop:)
		(append: ?output)[
			<br><br>
			(t8n: "dissolve") + (colour: black) + (text-style: "none")[
				You should 
				(link: "turn off the light")[
					(replace: ?output)[That's better.][(print:"abcd")]
				]
			]
		]
	]
}]

I imagine that I am ending the hook that is attached to the (link:) macro somewhere early, but I'm not sure how to fix that without screwing up the printed text. 

 

Separately, although it wouldn't matter in this particular case for me, how would I continue the same passage only if the link has been clicked, without entering a new passage? Without cramming it all into the (replace:) macro, if that would even be possible. In case I'm not making any sense, this is what I mean.

  1. All above carries out: blinking text, "turn off the light" appears, clicking turn off the light replaces it with "That's better."
  2. After a period of time, maybe 3 seconds, the rest of the passage (perhaps a description of the room with links to other passages) appears below.

Thanks a bunch!

...