When you follow a link to another passage, the $char
variable should contain the value that the player had cycled to.
So then you need a way to map “son” to “prince”, “daughter” to “princess”, and “child” to…uh…whatever that is. heir, maybe? There are a couple ways to do that.
The mapping is never going to change, so you don’t have to keep it in a story variable that gets copied into the history every turn: you might want to use SugarCube’s setup
object. In your StoryInit passage:
<<set setup.prince to new Map([ ['son', 'prince'], ['daughter', 'princess'], ['child', '...'] ])>>
Then where you want to use it you could say <<print setup.prince.get($char)>>
Or you could use a plain JavaScript object instead of a Map. The syntax is slightly shorter, but it is theoretically possible for some JS library to add properties to every object so you get extra entries, but that’s considered bad form so I suspect it’s vanishingly rare these days. And anyway you’re going to set all the entries you care about, so it would overwrite any default property from wherever. That’s:
<<set setup.prince to { "son": "prince", "daughter": "princess", "child": "..."}>>
And <<print setup.prince[$char]>>
Edit: you might also find good stuff if you look up things about showing pronouns?