How to join an argument from a macro and a string without space?

If you are requesting technical assistance with Twine, please specify:
Twine Version: 2.3.14
Story Format: Sugarcube

I would like to make a re-usable pronoun widget, where i can give it the name of a character and it returns a pronoun for that character.

Example of my code:
The party healer is a <<listbox "$healer-gender>><<optionsfrom ["Male, "Female", "Non-Binary"]>><</listbox>>

<<widget "she">><<if $args[0] + "-gender" is "Male">>he<<elseif $args[0] + "-gender" is "Female">>she<<else>>they<</if>><</widget>>

Used like:
The healer casts Heal All. <<she healer>> fails!

This code just gives an error for the if statement.

Please edit your posts and place your code within code blocks (see </> on the editor bar), so we can actually see it properly.

1 Like

Well, first of all you’re missing a closing quotation mark in your optionsfrom macro, so that can’t be helping.

But in general, this might be easier if you used object properties instead of separate variables; I used widgets like this in my recent game and that’s how I did it.

So in StoryInit you would have:

<<set $healer to {gender : "Non-Binary"}>> (or whatever you want as a default)

And then your listbox would be:

<<listbox "$healer.gender>><<optionsfrom ["Male", "Female", "Non-Binary"]>><</listbox>>

And then your widget would look like:

<<widget "she">><<if $args[0].gender is "male">>he<<elseif $args[0].gender is "female">>she<<else>>they<</if>><</widget>>

And when you wanted to use it, you would call it the same way as you did in your example. It’s really a very small change, but it saves you from having to muck around with string concatenation the way you’re doing right now.

EDIT: Oh, no, sorry, you would want to call it using:

<<she $healer>>

The $ is important!

1 Like

Thank you so much! I’m still not 100% sure how, but that seems to work.
I was using something similar before this, but it didn’t work for me. Your solution is much better.

Yeah, the Sugarcube documentation basically assumes you already know JavaScript, so it doesn’t really cover “what is an object and how do you use it?”, but they’re incredibly useful once you get into more complex stuff like this.

This is something I found with a quick Google search, but this intro to objects looks pretty clear: JavaScript Objects

They basically work the same way in Sugarcube except that where the JS examples read:

const car = {type:"Fiat", model:"500", color:"white"};

In Sugarcube you would write:

<<set $car = {type:"Fiat", model:"500", color:"white"}>>
1 Like

I see… thank you. :smile:

1 Like

Side note: If you’re working with pronouns then you might want to take a look at Chapel’s Pronoun Templates from his “Custom Macro Collection” and the “Pronoun Templates” section found in my Twine/SugarCube sample code collection.

Hope that helps! :slight_smile: