Adding contractions to widget for switching grammar from singular to plural

Twine Version: version 2.3.15
Story Format: sugarcube

Hello! I’m using singular and plural pronouns in my game and wanted to make switching the grammar a bit easier than using an else/if macro every time by using widgets for the most common words that will need switched. I know pronoun templates can help with this, but this is my first game, I’m keeping it pretty small, and I learn by doing things the hard way, lol.

So here is one of the widgets, it works great. My problem is that I don’t know how to make it work with contracted words like “hasn’t” and “haven’t.” When I try to, Twine tells me it’s an invalid macro name. I’ve looked at all the official help guides and tried searching for how to add contractions but I haven’t been able to find anything.

<<widget "has">><<switch $pronouns_plural>><<case false>>has<<case true>>have<</switch>><</widget>>

You can’t use apostrophes in widget names. So, the simple answer is, just don’t do that. Instead, just call the widget “hasnt” (no apostrophe) and then you can still have it display “hasn't” (with an apostrophe).

That said, instead of using widgets, you might want to look into using SugarCube templates for this. You could even copy the code from the “Pronoun Templates” section of my Twine/SugarCube sample code collection for that, if you’d like. With that code you could, for example, put “?theyre” (no apostrophe) in your passage and it would automatically convert that to “he's”, “she's”, “they're”, or “it's”, depending upon the current pronoun setting.

If you do want to stick with widgets, then I note that you could shorten your code to just this:

<<widget "has">><<if $pronouns_plural>>have<<else>>has<</if>><</widget>>

Hope that helps! :slight_smile:

1 Like

I see, thank you so much for your help! With the pronoun template, is there a way to make it show whatever pronouns the reader chooses, meanwhile I’d just have to type “?they’re” Right now I have text boxes where readers type in their pronouns (with examples of what to put where) and I like the inclusiveness of it.

Also, I got an error (a bunch of them actually) when I visited your sample code page.

"An error has occurred. You may be able to continue, but some parts may not work properly.

Error [tw-user-script-0]: CSSStyleSheet.cssRules getter: Not allowed to access cross-origin stylesheet."

There were errors on the page as well, although I don’t know if they’re related. Weirdly enough, when I went to download the code, and then pressed the browser back button, the page showed up perfectly with no errors.

Thanks again!

Not as-is, but you could modify it if you wanted it to use any pronouns other than the ones already in it.

Like I said, you’d have to type “?theyre”, without the apostrophe. It will still display with an apostrophe, but you can’t include any apostrophes in a template name.

Weird. I just tested the page in Opera, Chrome, and Firefox and didn’t get any unexpected errors or warnings in any of them. Considering that it worked when you hit the back button and that I haven’t heard any similar reports, I’m going to guess that it was some temporary glitch. If it happens again, you might try hitting CTRL+F5 to do a full reload of the page.

Thanks for the report, though. I’ll keep an eye out if I see any other reports of that happening. :slight_smile:

“?theyre” I knew that. :sweat_smile: Okay, thanks again for your help!