Twine Version: 2.5.1
Story Format: Sugarcube 2.36.1
Hello! I am currently trying to make a pronoun widget for my npc characters. How could I make it so if they don’t click any of the options, I could just randomize it? Thank you!
Twine Version: 2.5.1
Story Format: Sugarcube 2.36.1
Hello! I am currently trying to make a pronoun widget for my npc characters. How could I make it so if they don’t click any of the options, I could just randomize it? Thank you!
You will probably want to use the either feature
In a passage titled StoryInit:
<<set $var to either("A", "B", "C")>>
Then display it with <<print $var>>
or use $var in your existing widget
That would be helpful if you could volunteer what you already have coded in your widget.
Thank you! I’ll try it later.
Apologies! I forgot to include it.
<<widget 'arleygenset'>>
<div class="arley"><span style="color:black">"The Bunny Server"
<br>
<br>
<label><<radiobutton "$bunnygen" "f">> Female</label> <label><<radiobutton
"$bunnygen" "m">> Male</label><label><<radiobutton "$bunnygen" "nb">> Non-binary</label></span></div>
<</widget>>
I’d go for an either(), just like @pbparjeter suggested, just at the start of the widget. thus the preferred gender initialized with a random value. Then, if the player clicks any radiobutton, it will automatically change (if necessary) to match whatever button has been clicked. Well, to be precise it will change only when the player will click a link or a button to go further either in the passage or to another passage:
<<widget 'arleygenset'>>
<<set $bunnygen to either("f","m","nb")>>
<div class="arley"><span style="color:black">"The Bunny Server"
<br>
<br>
<label><<radiobutton "$bunnygen" "f">> Female</label> <label><<radiobutton
"$bunnygen" "m">> Male</label><label><<radiobutton "$bunnygen" "nb">> Non-binary</label></span></div>
<</widget>>
If you’re comfortable with javascript, you could use a random function.
//This determines if the Ring Toss is successful
let RingToss = [
{chance: "fail", rt: "You toss the rope up towards the ring, it just misses and comes straight back down, hitting you in the eye."},
{chance: "success", rt: "You toss the rope up towards the ring, it sails straight through the ring and comes back down, stopping just short of hitting you in the eye."}
];
function pickToss(arr) {
var index = Math.floor(Math.random() * arr.length);
return arr[index];
}
var toss = pickToss(RingToss);
State.variables.chance = toss.chance;
State.variables.result = toss.rt;
Thanks, it worked.