Widget printing link text?

Twine Version: Sugarcube 2.35.0

My story has a toggle setting for third-person/second-person prose.

<<widget 'ProseSetting'>>\
    <<if $POV2>>\
        <<link "Enable Third-Person">><<set $POV2 to false, $POV3 to true>><<dialogclose>><<dialog>><<include 'Settings'>><<onclose>><<run Engine.show()>><</dialog>><</link>>
        <<link "Enable Second-Person">><<set $POV2 to true, $POV3 to false>><<dialogclose>><<dialog>><<include 'Settings'>><<onclose>><<run Engine.show()>><</dialog>><</link>>

As such, the player may be referred to in either POV. The player name is also stored in a variable: $Kai. So to print the player’s name using the proper POV, I used the following widget:

<<widget "Kai">>\
    <<if $POV2>>You<<else>>$Kai<</if>>\

Now, I want a link with text including the player’s name. Such as, “Kai braked, stopping.” I tried a few different methods, but the only one I can seem to get working is this one:

<<if $POV2>>
    [[You braked, stopping|FirstAct3]]
    [[$Kai + " braked, stopping"|FirstAct3]]

This solution works, but it’s inconvenient to use in many passages, especially ones that use pronouns, like “Kai braked, stopping his bike”. In that case I’m also using a “his” widget that serves a similar function, further complicating the link text. Note: Just like the player may change her name to something other than “Kai”, $his may be stored as the string value “her” if the player is female.

<<widget "his">>\
    <<if $POV2>>your<<else>>$his<</if>>\

What I really want is something simple like [[<<Kai>> + " braked, stopping"|FirstAct3]]., but Twine wants an expression instead of the widget. Is there another way to include the result of my widget in the link text? If it was just a variable it wouldn’t be a problem, but I’m not sure how to do it with a widget. I tried setting a temp variable to the widget output and couldn’t get that working either.

You could use a <<link>> as that allows some markup. For example:

<<link "<<Kai>> braked, stopping" "FirstAct3">><</link>>

Alternatively. You could make a function that you could use in places you cannot use your widget. For example:

[[kai() + " braked, stopping"|FirstAct3]]

The function: (goes into your Story JavaScript)

window.kai = function () {
	const sv = State.variables;
	return sv.POV2 ? 'You' : sv.Kai;