0 votes
by (470 points)

Hello. I'm trying to get a stylized text that the player will choose. For this, I use two widgets, before and after the text.

Widgets:

<<widget "voice">>\
	<<if $player.voice is "gently">>\	
		@@.pcspeech_gently;\
	<</if>>\
	<<if $player.voice is "rude">>\
		@@.pcspeech_rude;\
	<</if>>\
	<<if $player.voice is "breathy">>\
		@@.pcspeech_breathy;\
	<</if>>\
	<<if $player.voice is "ringing">>\
		@@.pcspeech_ringing;\
	<</if>>\
<</widget>>\

<<widget "voice_end">>\
	@@
<</widget>>\

use:

<<voice>>asd<<voice_end>>

as a result, the text remains without a style. But if i use that style without widgets, style works 

1 Answer

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

Unfortunately, you cannot split markup or tags (macro or HTML) which have opening and closing sequences between widgets as you're attempting to do.

Since widgets do not currently support being containers (i.e. having an opening and closing tag), you'll probably want either a container macro or to pass the text to the widget as an argument.

EDIT: I'll provide some examples a bit later.  I'm on my phone at the moment.

by (62.7k points)

Rather than using control logic to select the appropriate class name, both of the following examples use the fact that, based on your example, the value of $player.voice seems to match the latter half of your class names.  Thus, you may simply use it to build the class name, no control logic required.

 

Example - Widget Arguments

Widget:

<<widget "voice">>
	\<<= '@@.pcspeech_' + $player.voice + ';' + $args[0] + '@@'>>
\<</widget>>

Usage:

<<voice "Hello. My name is Inigo Montoya. You killed my father. Prepare to die.">>

 

Example - Container Macro

Macro: (goes in Story JavaScript or the equivalent)

/*
	<<voice>>
*/
Macro.add('voice', {
	skipArgs : true,
	tags     : null,
	handler  : function () {
		if (this.payload[0].contents !== '') {
			var sv = State.variables;

			jQuery(document.createElement('span'))
				.addClass('pcspeech_' + sv.player.voice)
				.wiki(this.payload[0].contents)
				.appendTo(this.output);
		}
	}
});

Usage:

<<voice>>Hello. My name is Inigo Montoya. You killed my father. Prepare to die.<</voice>>

 

by (470 points)
oh my, thats really works! Thank you!
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...