Variable values not showing up properly

Hello! I am using Twine 2 on the website version and Sugarcube 2.36.1.
There seems to be a problem when I code an if statement. I start with the radiobutton choices first.

<div class="wbox"><span style="color:black"> <<radiobutton "$prn" "She">> She/Her <<radiobutton "$prn" "He">> He/Him <<radiobutton "$prn" "They">> They/Them </span></div>

And then the if statement:

<<if $prn is "She">>
<<set $prna to 'she'>>
<<set $prnb to 'her'>>
<<set $prnc to 'hers'>>
<<elseif $prn is "He">>
<<set $prna to 'he'>>
<<set $prnb to 'him'>>
<<set $prnc to 'his'>>
<<elseif $prn is "They">>
<<set $prna to 'they'>>
<<set $prnb to 'them'>>
<<set $prnc to 'theirs'>>
<</if>>

However, when I choose They/Them or He/Him, it prints “she/her/hers” instead. Is there anything wrong with my coding?

1 Like

Hi!
I can’t find any issues within the code you posted. Where are you checking/printing the resulting variables? If it’s in the same passage that has the radiobuttons, the printed values won’t update when you change your selection - they only change upon the passage transition (unless you use replace).

1 Like

Is the sequence of <<if>> macro calls within the same Passage as the <<radiobutton>> macro calls?

If they are then you will need to delay the execution of the <<if>> macro calls, otherwise they will be executed before the end-user has had a chance to interact with the radio buttons. And changing the value of a variable does not cause the automatic re-execution of any code that makes reference to that variable.

One method you can use to delay the execution of code is you place it within a <<link>> or <<button>>

<<link "Update Pronouns">>
	<<if $prn is "She">>
		<<set $prna to 'she'>>
		<<set $prnb to 'her'>>
		<<set $prnc to 'hers'>>
	<<elseif $prn is "He">>
		<<set $prna to 'he'>>
		<<set $prnb to 'him'>>
		<<set $prnc to 'his'>>
	<<elseif $prn is "They">>
		<<set $prna to 'they'>>
		<<set $prnb to 'them'>>
		<<set $prnc to 'theirs'>>
	<</if>>
<</link>>
1 Like

Nope, they were both in different passages. I entered the if statement after the passage that contained the radiobutton. I have no idea why it does that

thank you so much! I put it in the same passage using your code and it worked :smiley: