I’m just asking this out of curiosity rather than for a specific application - when I was writing in Choicescript last year, the multireplace feature was by far my favourite thing about it, and I was wondering if anyone had tried to recreate a similar function in Twine?
If you’re not familiar, multiplace allows you to quickly display different text depending on a variable state. It’s brilliant for making short sections of in-paragraph text responsive to player choices where a full if/else section would be a bit bulky. Example from my last game below:
Previously, you @{(jowplan) promised Jowanet that you would be there when she carried out her plans.|lied to Jowanet, saying you would go along with her plan though you had no intention of doing so.|flatly refused to participate in Jowanet's plan.} Do your intentions remain the same?
I greatly prefer Twine’s flexibility to Choicescript overall but I do miss being able to add lots of dynamic text in a really elegant way, and I was curious as to whether anyone else had felt the same and tried to recreate this in Sugarcube?
Not really no. The multireplace is essentially an if/else statement. You could potentially use <<switch>> if it’s just one variable, but you’ll end up with similar amount of code at the end.
What I tend to do is use <<widget>> (docu) to “hide” bulky variations in story passages. So instead of:
lorem ipsum <<if $var is 1>>variation 1<<elseif $var is 2>> variation 2<<else>>otherwise<</if>>
you have
lorem ipsum <<widgetvariation>>
(and then the conditional statement in the widget-tagged passage)
<<set $test = true>>
With test variable being true: <<booleanMulti $test "hello world" "thank you world">>
<<set $test = false>>
With test variable being false: <<booleanMulti $test "hello world" "thank you world">>
so for your example… (note this only has the 1st two arguments)
<<set $jowplan = true>>
Previously, you << booleanMulti $jowplan "promised Jowanet that you would be there when she carried out her plans." "lied to Jowanet, saying you would go along with her plan though you had no intention of doing so.">> Do your intentions remain the same?
The one where you’re automagically detecting the number of arguments and mapping them to the number you set the variable to would take more doing.
ETA: this can also be combined with variables and line breaks like the choicescript multireplace, just due to Twine’s parsing of printed variables and \n (the line break)! you could probably use a naked variable to simplify the widget code even more for strings, but I think <<print>> is probably better, because it can do functions etc.
<<set $jowplan = false>>
<<set $name = "Jowanet">>
Previously, you <<booleanMulti $jowplan "promised $name that you would be there when she carried out her plans.\nHow nice!\n" "lied to $name, saying you would go along with her plan though you had no intention of doing so.\n\nHow devious!\n\n">> Do your intentions remain the same?```
I think I figured out how to do the automatic detection of numbers thing! It’s not as nice as the choicescript syntax, but still pretty nice imo – it uses the capture keyword in <<widget>>, so the variable you’re checking will be passed in as the 1st argument, the strings you want to include will be within the tags (separated by |) and you’ll need a closing tag (here it’s <</numbersMulti>>.
<<set $name = "Jowanet">>
<<set $plan = 1>>
With plan variable set to 1: Previously you <<numbersMulti $plan>>promised $name that you would be there when she carried out her plans.|lied to $name, saying you would go along with her plan though you had no intention of doing so.|flatly refused to participate in $name's plan.<</numbersMulti>> Do your intentions remain the same?
<<set $plan = 2>>
With plan variable set to 2: Previously you <<numbersMulti $plan>>promised $name that you would be there when she carried out her plans.|lied to $name, saying you would go along with her plan though you had no intention of doing so.|flatly refused to participate in $name's plan.<</numbersMulti>> Do your intentions remain the same?
<<set $plan = 3>>
With plan variable set to 3: Previously you <<numbersMulti $plan>>promised $name that you would be there when she carried out her plans.|lied to $name, saying you would go along with her plan though you had no intention of doing so.|flatly refused to participate in $name's plan.<</numbersMulti>> Do your intentions remain the same?
here’s the usage with line breaks for readability. Note that \n won’t work here, but line breaks will be rendered as-is like in the rest of SugarCube:
With plan variable set to 1: Previously you
<<numbersMulti $plan>>
promised $name that you would be there when she carried out her plans.|
lied to $name, saying you would go along with her plan though you had no intention of doing so.|
flatly refused to participate in $name's plan.
<</numbersMulti>>
Do your intentions remain the same?
If you set the variable to something higher than the number of arguments you provided, there won’t be any errors, it just won’t print anything
ETA: Also note! Putting the code to parse booleans and to parse numbers into the same widget would probs be tedious and complicated. Easier to just keep them as two separate widgets.
I created a widget in my current Sugarcube project that can handle between 2 and 4 links, and it builds a nice centered table and a bulleted list of choices for the player.
In the particular game I’m using this in, the game only offfers a black background with white text, so I defined a helper widget to go along with the main widget — to provide orange (highly visible) error messages if the widget isn’t passed copacetic data.