How do you change npc's name and gender based off your sexual preference?

In my game there will be opposite sexed twins. One will be a main npc. And for example, those twins are Chris and Michelle. How do you code it where your preference will change Chris into Michelle if your mc is a heterosexual male or homosexual female, Michelle into Chris if your mc is a heterosexual female or a homosexual male, or a random gender if your mc is either bi or asexual?

And if possible, can I have it so the other twin will have a small appearance, or maybe mentioned through dialog?

1 Like
*if ((heterosexual) and (male))
    *set RO1_name "Chris"
*if ((homosexual) and (female))
    *set RO1_name "Chris"
*if ((heterosexual) and (female))
    *set RO1_name "Michelle"
*if ((homosexual) and (male))
    *set RO1_name "Michelle"

And for the randomization part, as the variables should go on top of the startup.txt, create a numeric variable like, randomized_RO1_name 0 so;

*create randomized_RO1_name 0

*if ((bisexual) or (asexual))
    *rand randomized_RO1_name 1 2
*comment The 1 2 part at the end of *rand command is to 
*comment give it an interval so it knows in which gap to randomize.

*if (randomized_RO1_name = 1)
    *set RO1_name "Chris"
*if (randomized_RO1_name = 2)
    *set RO1_name "Michelle"   

For the appearance you might want to have one more variable which tells if it is Michelle or Chris, so;

*comment On top of startup.txt again
*create twin_name ""
*create twin_name_michelle false

*if (RO1_name = "Chris")
    *set twin_name_michelle true
    *set twin_name "Michelle"
*if (RO1_name = "Michelle")
    *set twin_name "Chris"

*comment then to make it appear you can use multireplace;

${RO1_name}'s twin was @{twin_name_michelle Michelle | Chris}.

*comment twin_name variable is optional here, 
*comment but if you don't want to use multireplace everythime 
*comment you can use twin_name for

${RO1_name}'s twin was ${twin_name}.
*comment OR use multireplace to your advantage like
${RO1_name}'s twin @{twin_name_michelle sister | brother} was ${twin_name} 

2 Likes

The above is technically correct; however, don’t use only *if statements. Use *elseif/*else as well. It’ll make your life easier during testing.

2 Likes

But if you expand the if statement to elseif and elses you then have to use bunch of goto’s and labels. I don’t know how would that make it easier. Also I find this way more practical because of the same reason.

Is it easier to debug that way? Is it about error texts? Or playtest maybe…?

1 Like

I wholeheartedly disagree with that who will want five tons of labels and goto without sense. I have millions of problems with those gotos and labels without sense and fake errors for them as well. Absolutely no error using if and fake choices.

So basically all depends on how you use them and preferences. It is not better one way over the other

1 Like

Y’all, just use implicit control flow and then you rarely have to use labels. It is MUCH easier to test code using *elseif and *else. If you forget to check a specific condition using *if then you’re going to waste time tracking down an issue that *else prevents.

3 Likes

YES. Implicit control flow all the way, and then you can use elseifs and elses without any hassle, and basically force ChoiceScript to behave like a regular programming language.

Huh, sorry. :sweat_smile: I guess that’s off topic for this discussion. I just get carried away when it comes to programming best practices :stuck_out_tongue: (and unnecessary condition checking is just one of those things I was taught to avoid, and I’m irrationally upset by it :woman_shrugging: )

3 Likes

Here is my suggestion. I include some additional options in case they interest you.

You can literally copy and paste this into your software and it will work as is. You may need to remove, switch, or change the *create and *temp codes based on your needs.

Part 1 = Coding for Creating Main Character’s nos (name, orientation, sex) (You might like my suggestions, and it helps explain why I use the coding in Part 2 the way I do. I decided to create this coding as if I were doing what you wanted as if it were my own game to best help you, which is why Part 1 is included here.)
Part 2 = Coding for Twin’s Names
Part 3 = Verify the Coding Works (At the Bottom)
While I use labels for parts 1, 2, and 3, they are only there for your benefit, not for coding purposes.

*comment You can literally copy and paste this into your software and it will work as is. You may need to remove, switch, or change the *create and *temp codes based on your needs.

*create implicit_control_flow True
*create mc_name ""
*create mc_sex ""
*create mc_orientation ""
*create twin_1_name ""
*create twin_2_name ""
*create var_num 0
*comment the following create/temp commands are for if you want someone to have the option to review and change any of the choices
*create var ""
*create var2 False
*temp confirming_mc_nos False
*comment nos = Name, Orientation, and Sex
*temp mc_orientation_first_letter False

*label part_1
*comment Part 1: Main Character Creation (Useful for both a game and for Part 2 for helping you out.)
*label mc_name
What is your character's name?
*input_text mc_name
*if (confirming_mc_nos)
    *goto confirming_mc_nos

*label mc_sex
Do you want $!{mc_name} to be male or female?
*fake_choice
    #Male
        *set mc_sex "male"
    #Female
        *set mc_sex "female"
    *if not (confirming_mc_nos)
        #Undo: Change Character's Name
            *goto mc_name
*if (confirming_mc_nos)
    *goto confirming_mc_nos

*label mc_orientation
What is $!{mc_name}'s sexual orientation?
*fake_choice
    #Heterosexual
        *set mc_orientation "heterosexual"
        *set var_num 1
    #Homosexual
        *set mc_orientation "homosexual"
        *set var_num 2
    #Bisexual
        *set mc_orientation "bisexual"
    #Asexual
        *set mc_orientation "asexual"
    #Gender Neutral
        *set mc_orientation "gender-neutral"
    #Create My Own Orientation
        *comment Optional
        Type $!{mc_name}'s sexual orientation below.
        *input_text mc_orientation
        Does ${mc_orientation} lean towards being sexually attracted to men/masculine, women/feminine, both, or neither?
        *fake_choice
            #Men/Masculine
                *set var_num 1
            #Women/Feminine
                *set var_num 2
            #Both
                *set var_num 0
            #Neither / Doesn't Matter
                *set var_num 0
        *goto confirming_mc_nos
    #Undo: Change Character's Sex
        *goto mc_sex

*label confirming_mc_nos
*set confirming_mc_nos True
*set var mc_orientation#1
*if (((var = "a") or  (var = "e")) or ((var = "i") or (var = "o"))) or (var = "u")
    *set var2 True
*else
    *set var2 False
Your main character is @{var2 an | a} ${mc_orientation} oriented ${mc_sex} named $!{mc_name}. Do you want to change anything?
*fake_choice
    #Change Name
        *goto mc_name
    #Change Sexual Orientation
        *goto mc_orientation
    #Change Sex
        *goto mc_sex
    #Everything Looks Good
        *set confirming_mc_nos False

*label part_2
*comment PART 2: Coding for Twin's Names
*label choose_romantic_partners_name
*comment Option for player to create the name of the main character's romantic partner.
Do you want the name for your main character's romantic partner to have a traditionally male name, female name, or gender-neutral name, or do you want to create the name, or do you want to be surprised?
*fake_choice
    #Male name
        *set var_num 2
    #Female name
        *set var_num 1
    #Gender-neutral name
        *set var_num 0
    #I want to create the name
        *label create_twins_name
        Type in the name of the main character's romantic partner below.
        *input_text twin_1_name
        You wrote $!{twin_1_name}. Are you happy with this?
        *fake_choice
            #Yes
                *goto part_3
            #No
                *goto create_twins_name
            #Go Back to Prior Menu
                *goto choose_romantic_partners_name
    #Surprise me!
        *rand var_num 0 2
*comment End of the option for the player to create the name of the twin.

*label twins_names
*comment Twin 1 gets a female name, and twin 2 gets a male name.
*if (var_num = 1)
    *if (mc_name = "Michelle")
        *set twin_1_name "Angelica"
        *set twin_2_name "Chris"
    *else
        *set twin_1_name "Michelle"
        *if mc_name = "Chris"
            *set twin_2_name "George"
*comment Twin 1 gets a male name, and twin 2 gets a female name.
*elseif (var_num = 2)
    *if (mc_name = "Chris")
        *set twin_1_name "George"
        *set twin_2_name "Michelle"
    *else
        *set twin_1_name "Chris"
        *if mc_name = "Michelle"
            *set twin_2_name "Angelica"
        *else
            *set twin_2_name "Michelle"
*comment Twins 1 and 2 get gender-neutral names.
*else
    *if (mc_name = "Sam")
        *set twin_1_name "Jordan"
        *set twin_2_name "Logan"
    *elseif (mc_name = "Jordan)
        *set twin_1_name "Sam"
        *set twin_2_name "Logan
    *else
        *set twin_1_name "Sam"
        *set twin_2_name "Jordan"

*label part_3
*comment For Testing Purposes Only
*label chapter_one
For Testing Purposes:
*line_break
mc's name: $!{mc_name}
*line_break
mc's sex: ${mc_sex}
*line_break
mc's orientation: ${mc_orientation}
*line_break
twin 1's name: $!{twin_1_name}
*line_break
twin 2's name: $!{twin_2_name}
*page_break Finished Testing Review
*comment End of Testing Section

I hope this helps you. Let me know what you think.

One way to avoid a ton of IF statements, by the way, is to use multireplace. For example…

Hello! Let's create your character.

First, how would you describe your gender?

*comment I only put three options here, but you could extend this. Just make sure to keep track of how many options so that when you use multireplace you have a value for each one.
*choice
    #Male
        *set mc_num 2
        *goto pronouns
    #Female
        *goto pronouns
    #Nonbinary
        *set mc_num 3
        *goto pronouns

*label pronouns
Thank you! Now, what are your pronouns?

*choice
    #He, Him
        *set mc_pro_num 2
        *goto sexuality
    #She, Her
        *goto sexuality
    #E, Em
        *set mc_pro_num 3
        *goto sexuality
    #They, Their
        *set mc_pro_num 4
        *set mc_plural true
        *goto sexuality

*label sexuality
Next, how would you define your sexuality?
*comment 1=female 2=male 3=nonbinary
*choice
    #I'm straight.
        *set mc_pref_num 1
        *set twin_num "@{mc_num 2|1|3}"
        *if twin_num=3
            *rand twin_num 1 2
        *goto mc_set
    #I'm gay.
        *set mc_pref_num 2
        *set twin_num "@{mc_num 1|2|3}"
        *goto mc_set
    #I'm bi.
        *set mc_pref_num 3
        *rand twin_num 1 3
        *goto mc_set
    #I'm ace.
        *rand twin_num 1 3
        *goto mc_set

*label mc_set
All right. All we need now is your name.
*set mc_e "@{mc_pro_num she|he|e|they}"
*set mc_em "@{mc_pro_num her|him|em|them}"
*set mc_eir "@{mc_pro_num her|his|eir|their}"
*set mc_eirs "@{mc_pro_num hers|his|eirs|theirs}"
*set mc_emself "@{mc_pro_num herself|himself|emself|themself}"

*choice
    #@{mc_num Alice|Ben|Alex}
        *set mc_name "@{mc_num Alice|Ben|Alex}"
        *goto twin_set
    #Harper
        *set mc_name "Harper"
        *goto twin_set
    #Why don't I just type it in?
        Please enter your name here. Don't forget to capitalize it.
        *input_text mc_name
        *goto twin_set

*label twin_set
*comment info for twin npc
*set twin_2_num "@{twin_num 2|1|3}"
*if twin_2_num=3
    *rand twin_2_num 1 2
*set tw_e "@{twin_num she|he|e}"
*set tw_em "@{twin_num her|him|em}"
*set tw_eir "@{twin_num her|his|eir}"
*set tw_eirs "@{twin_num hers|his|eirs}"
*set tw_emself "@{twin_num herself|himself|emself}"
*set tw_e_2 "@{twin_2_num she|he|e}"
*set tw_em_2 "@{twin_2_num her|him|em}"
*set tw_eir_2 "@{twin_2_num her|his|eir}"
*set tw_eirs_2 "@{twin_2_num hers|his|eirs}"
*set tw_emself_2 "@{twin_2_num herself|himself|emself}"
*set twin_1 "@{twin_num Michelle|Chris|Avery}"
*set twin_2 "@{twin_2_num Michelle|Chris|Quinn}"

All right, ${mc_name}! Now for some backstory. You grew up with ${twin_1}, an awesome @{twin_num gal|guy|friend}. $!{tw_e} has a twin named ${twin_2}. You don't know ${tw_em_2} very well, though.
*finish

And here is what I have in start-up


*comment info for main character
*create mc_num 1
*comment 1=female 2=male 3=nonbinary
*create mc_pro_num 1
*comment 1=she 2=he 3=e 4=they
*create mc_plural false
*create mc_pref_num 1
*comment 1=het 2=hom 3=bi 4=ace
*create mc_name ""
*create mc_e ""
*create mc_em ""
*create mc_eir ""
*create mc_eirs ""
*create mc_emself ""

*comment info for twin npc
*create twin_1 ""
*create twin_2 ""
*create twin_num 1
*comment twin_num can also serve as a basic ro_num
*create twin_2_num 1
*create tw_e ""
*create tw_em ""
*create tw_eir ""
*create tw_eirs ""
*create tw_emself ""
*create tw_e_2 ""
*create tw_em_2 ""
*create tw_eir_2 ""
*create tw_eirs_2 ""
*create tw_emself_2 ""

(Side note: I personally don’t use implicit control because I’ll add things later on or re-arrange things. Or I’ll write choices in one place and the related scenes in another so that I can keep all the choices close together visually in the code, etc. I lose track of the flow. It is easier just to mark out exactly where everything is going to go and not worry.)

(ETA: That said, I don’t think I’ve ever used this many *choice commands instead of *fake_choice. If you keep everything in this order, you can pull out the labels and change everything to *fake_choice and remove the goto commands).

3 Likes

Thank you all for the responds. It’s a lot to absorb since I’m not good with coding. Now that I’m off, I will try those solutions.

2 Likes

Those solutions didn’t work. I tried different versions of them too. I’m probably overcomplicated everything. So instead, I’ll just settle with help changing the npc male or female based of your gender preference. I’ve asked before but haven’t got a solution that works. And thank you all for the help.

What about them didn’t work? I know I tested mine with quicktest before I shared it.

What is the error text you got @NewNameSameBro ? Maybe we can help if we know that.

Wow. I didn’t expect a quick respond. I’m not sure. All I get is an error with no explanation. I don’t know how to do quicktest but found a way to check for errors through Internet Explorer. What I do is I pull up mygame with Explorer and I do a quick playthrough to see if any new code I add will get an error. And that is what is not working. I got an error with all the solutions.

Just paste here whatever error message you’re getting. Even if the msg doesn’t specify any specific line, it still gives us some clue as to what happened.

And your browser got frozen is an error condition, not “error with no explanation.”

What I meant was there is no explanation when the error message pops up. It’s blank with just the word “error.” I’m not sure what you mean by “a specific line.” If you can explain how to use quicktest that might help me out a lot. I tried along time ago and it didn’t respond, so I quit trying and found a way to check for errors through Internet Explorer; which I’m guessing you’re not suppose to? Also if it helps, everytime I try to open the game with Firefox it says something like “startup txt is missing, can’t load.”

Opening the “/web/mygame/index.html” using any browser shouldn’t produce any problem. I never used quicktest so far and do rely on manual local testing. Were you asked to “upload” folders when you try to do local testing?

What are you using to write your code? If you’ve not tried out CSIDE yet, I highly rec checking it out. It lets you test within the IDE. Plus you can run quicktests from a dropdown menu. It also highlights your code nicely for you. See: [CSIDE] The ChoiceScript IDE (v1.3.0 Now Available — 18/06/2019)

1 Like

I do everything inside CSIDE. I don’t test in the web browser myself, even though I know how. It is just easier in CSIDE.

No I wasn’t asked. The problem only happens with Firefox which is why I use Internet Explorer.