How to make three pronouns w/ sugarcube

Twine V. 2.3.15, SugarCube and Javascript.
Hello everyone, I am brand new to game development with Twine, but have been enjoying it a lot. I had one (multi-part) question. I am doing a character creation thing that specifically asks for pronouns, and I have three options. None of them seem to work how I want it to though, occasionally it will work for only one option, but I think I am going wrong with the actual selection, like the listbox isn’t executing the commands properly. I am envisioning and drop-down menu that the player can select their pronouns from, and then from there they would be set in stone so during the course of the story I can just write whichever $ command is grammatically appropriate for their chosen pronoun. Should I be doing this in the StoryInit passage? Or can I just cram all the ‘if’s’ into the same passage as the listbox? I am very new, so any help would be tremendously appreciated.

<<listbox "$pronouns">>
	<<option 'She/Her' set $pronouns to "1">>
	<<option 'He/Him' set $pronouns to "2">>
	<<option 'They/Them' set pronouns to "3">>
<</listbox>>
<<if $pronouns is "1">>
	<<set $heshe to 'she'>>
	<<set $capitalheshe to 'She'>>
	<<set $hisher to 'her'>>
	<<set $capitalhisher to 'Her'>>
	<<set $himher to 'her'>>
	<<set $capitalhimher to 'Her'>>
	<<set $hishers to 'hers'>>
	<<set $capitalhishers to 'Hers'>>
	<<set $himselfherself to 'herself'>>
	<<set $capitalhimselfherself to 'Herself'>>
<</if>>
<<if $pronouns is "2">>
	<<set $heshe to 'he'>>
	<<set $capitalheshe to 'He'>>
	<<set $hisher to 'his'>>
	<<set $capitalhisher to 'His'>>
	<<set $himher to 'him'>>
	<<set $capitalhimher to 'Him">>
	<<set $hishers to 'his'>>
	<<set $capitalhishers to 'His'>>
	<<set $himselfherself to 'himself'>>
	<<set $capitalhimselfherself to 'Himself'>>
<</if>>
<<if $pronouns is "3">>
	<<set $heshe to 'they'>>
	<<set $capitalheshe to 'They'>>
	<<set $hisher to 'theirs'>>
	<<set $capitalhisher to 'Theirs'>>
	<<set $himher to 'them'>>
	<<set $capitalhimher to 'Them'>>
	<<set $hishers to 'theirs'>>
	<<set $capitalhishers to 'Theirs'>>
	<<set $himselfherself to 'themselves'>>
	<<set $capitalhimselfherself to 'Themselves'>>
<</if>>

You don’t use the set to thing there: just the option name that will be displayed to the player, and then the value that the variable will be set to. The <<listbox>> should do the rest of the work: you’re telling it to store the value in $pronouns.

You also don’t need quote marks around the number: JavaScript (and hence Twine) translates between numbers and strings automatically most of the time, but if you want a number it’s better to just use a number (instead of putting quotes around it so it’s treated as text).

And actually, you don’t need the number at all. If you leave out the second value entirely, the listbox will just set $pronouns to 'She/Her' or whatever. You’ll have to be careful about getting the capitalization exactly right when you compare it, but…

You should probably use <<elseif>> instead of entirely separate <<if>> statements here. If you use <<elseif>> then you’re guaranteed that only one of them will run. With separate <<if>> statements it’s theoretically possible that more than one section could run: in code this simple it’s highly unlikely that you’d make a mistake that would cause the condition checks to overlap, but if you do something more complicated, it could happen, so it’s a good habit to get into.

So I’d do the listbox like this:

<<listbox "$pronouns">>
	<<option 'She/Her'>>
	<<option 'He/Him'>>
	<<option 'They/Them'>>
<</listbox>>

And then in another passage (after the one where the user selects):

<<if $pronouns is 'She/Her'>>
	<<set $heshe to 'she'>>
	<<set $capitalheshe to 'She'>>
	<<set $hisher to 'her'>>
	<<set $capitalhisher to 'Her'>>
	<<set $himher to 'her'>>
	<<set $capitalhimher to 'Her'>>
	<<set $hishers to 'hers'>>
	<<set $capitalhishers to 'Hers'>>
	<<set $himselfherself to 'herself'>>
	<<set $capitalhimselfherself to 'Herself'>>
<<elseif $pronouns is 'He/Him'>>
	<<set $heshe to 'he'>>
	<<set $capitalheshe to 'He'>>
	<<set $hisher to 'his'>>
	<<set $capitalhisher to 'His'>>
	<<set $himher to 'him'>>
	<<set $capitalhimher to 'Him">>
	<<set $hishers to 'his'>>
	<<set $capitalhishers to 'His'>>
	<<set $himselfherself to 'himself'>>
	<<set $capitalhimselfherself to 'Himself'>>
<<elseif $pronouns is 'They/Them'>>
	<<set $heshe to 'they'>>
	<<set $capitalheshe to 'They'>>
	<<set $hisher to 'theirs'>>
	<<set $capitalhisher to 'Theirs'>>
	<<set $himher to 'them'>>
	<<set $capitalhimher to 'Them'>>
	<<set $hishers to 'theirs'>>
	<<set $capitalhishers to 'Theirs'>>
	<<set $himselfherself to 'themselves'>>
	<<set $capitalhimselfherself to 'Themselves'>>
<</if>>

You need to do the if statements on a separate passage than the listbox, because if you do it in the same one, then it’ll display the listbox, then run the if statements immediately, but the player hasn’t made a choice yet: they’ve only just been shown the listbox. I’m not sure the best way to do that: if you’re linking to another passage after the player selects their pronouns, maybe you can just put the if statements there.

I know there are a couple people who have pre-made pronouns code so probably one of them will have a better idea of the best way to do it…

You might want to check out the “Pronoun Templates” section of my Twine/SugarCube sample code collection for a version of that which uses SugarCube’s Template API to display the correct pronouns.

Enjoy! :slight_smile:

In addition to the excellent advices above, as a side note I wish to add that you can use toUpperFirst() https://www.motoslave.net/sugarcube/2/docs/#methods-string-prototype-method-toupperfirst when you need a first capital letter. Example:

<<print $himher.toUpperFirst()>> arm lunges towards the coffee pot.

will return Her/Him/Them depending on what $himher is in the first place, so you can cut your variables by half.

It’s working perfectly now! Thank you so much bro <3

I know this might be a bit late to ask but would you know why they/them wouldn’t work, it just says [undefined] while she/her and he/him does work

Hi Kat, can you post the code you are using? The one that Josh typed out works for me.

Hey, I tried the exact same one but when I get home tonight I can copy and paste it onto here👍If that’s alright.
I did try what soup said with the print so maybe that is it? But I did also try just <<print $himher>> but still didn’t work, she/her and he/him pronouns work perfectly just not they/them

Of course! I am not much of a coder, but I will try to help out.
Once the pronouns have been set by the textbox, you don’t need to specify print. You can just type plain $hishers in the passage and it will say ‘theirs’ (or whichever they choose) when the story is being run.
If it’s only the They/Them that isn’t working, then there may be a small typo or something in the set passages, paste it here and I will look through it with you.

i used the same as you but here is the parts

<<listbox “$pronouns”>>
<<option ‘She/Her’>>
<<option ‘He/Him’>>
<<option ‘They/Them’>>
<>

and this is well the other thing

<<if $pronouns is ‘She/Her’>>
<<set $heshe to ‘she’>>
<<set $capitalheshe to ‘She’>>
<<set $hisher to ‘her’>>
<<set $capitalhisher to ‘Her’>>
<<set $himher to ‘her’>>
<<set $capitalhimher to ‘Her’>>
<<set $hishers to ‘hers’>>
<<set $capitalhishers to ‘Hers’>>
<<set $himselfherself to ‘herself’>>
<<set $capitalhimselfherself to ‘Herself’>>
<<elseif $pronouns is ‘He/Him’>>
<<set $heshe to ‘he’>>
<<set $capitalheshe to ‘He’>>
<<set $hisher to ‘his’>>
<<set $capitalhisher to ‘His’>>
<<set $himher to ‘him’>>
<<set $capitalhimher to 'Him">>
<<set $hishers to ‘his’>>
<<set $capitalhishers to ‘His’>>
<<set $himselfherself to ‘himself’>>
<<set $capitalhimselfherself to ‘Himself’>>
<<elseif $pronouns is ‘They/Them’>>
<<set $heshe to ‘they’>>
<<set $capitalheshe to ‘They’>>
<<set $hisher to ‘theirs’>>
<<set $capitalhisher to ‘Theirs’>>
<<set $himher to ‘them’>>
<<set $capitalhimher to ‘Them’>>
<<set $hishers to ‘theirs’>>
<<set $capitalhishers to ‘Theirs’>>
<<set $himselfherself to ‘themselves’>>
<<set $capitalhimselfherself to ‘Themselves’>>
<>

do you think its cause the $heshe doesn’t have they in it?

You start your characters string with a simple quote and end it with a double quote, that may be the reason why it’s not working.

2 Likes

im so sorry I’m a newbie and this might sound very stupid to ask but how would I change that?

You either change your simple quote to a double quote or the reverse. The reverse is probably better as it would be consistent with what you did everywhere else.

1 Like

Thankyou so much, its working now, I put it all double quotes instead of single ones and now it works. thanks for the help