Randomizing variables

My apologies in advance if this has already been asked.

Hello, I’ve another question on another fine day. For the game I’m creating, there’s a customization portion in the beginning. The player, essentially, creates their own Hylian. This will be the character used to progress through the storyline. I looked at some older posts for a name with player input, so I’m done with that portion. Now, I have variables I need to set. I have one for gender/pronouns, name and romantic preference. How would I create another for hair color? That also asking about eye color, this is so it would be more… “realistic” in a way. It would be completely randomized, so it might look something like this after the player is done customizing their character:

Great! Your name is $name and you are a blond(e) [male, female OR non-binary] Hylian with blue eyes.

But it could also look similar to this:

Great! Your name is $name and you are a ginger [gender variable] Hylian with green eyes.

Not to say that they have to be exactly like that, as in common combinations. The character could have brown hair and blue/green eyes, blond/orange hair with brown eyes. There are also grey eyes that I want to include, and black hair. Another example is:

Great! Your name is $name and you are a black haired [gender variable] Hylian with grey eyes.

All of it would be randomized and I would love to add that aspect to the game. Also, how would I go back to it if I ever refer to the character’s hair/eye color? By that I mean, an NPC like the king could refer to the character like this:

"$name, you are a new knight in this academy. Come forth to this pedestal and look at me, sincerely, to oath your loyalty to the royal family."

- The character moves closer

"$name, with the trust I put in you, I bestow upon you the title of Zelda's new bodyguard, please take care of her. I am entrusting my daughter's safety in you. May your $eyecolor eyes not be deceitful in your honor."

Would I use the variable $eyecolor? Or is there something I may be missing?

For any further clarification in a way to simplify what I’ve already written:

Is it possible to make a randomized variable for hair and eye color that can later be referred back to in a different passage?

Thank you for any help, I can clarify further if necessary.

Twine Version: 2.3.16
Story Format: Sugarcube 2.36.1

You can just do something using the either() function like this:

<<set $eyes = either("blue", "brown", "green", "grey")>>
<<set $hair = either("black", "brown", "red", "blond")>>
<<if $gender == "female" && $hair = "blond">>
    <<set $hair = "blonde">>
<</if>>

and then you could display that like this:

Great! Your name is $name and you're a $gender Hylian with $hair hair and $eyes eyes.

You can use the same technique of randomly pulling from a collection of values like that for anything else you want to randomize.

I’d recommend skimming through the SugarCube documentation for various other randomization methods (just search the page for instances of the word “random”), since there are several other functions and methods there which are useful in different situations.

Have fun! :slight_smile: