Gosub for randomizing NPC genders?

Hello,

I want to randomize NPC genders without linking them to the player’s. Much obliged if you’d let me know whether or not I’m on the right track with coding. Variables limited for brevity’s sake.

If I did this:

*create npcheshenb ""
*create npchishernb ""
*create variable 1

Is this the right way to gosub:

*rand variable 1 3
*if variable = 1
    *gosub male
		
*elseif variable = 2
    *gosub female
		
*elseif variable = 3
    *gosub nonbinary

*label male
*set npcheshenb "he"
*set npchishernb “his”
*return

*label female
*set npcheshenb "she"
*set npchishernb “her"
*return

*label nonbinary
*set npcheshenb “the boss"
*set npchishernb “the boss’"
*return

To code for situations like this throughout the body of the text?

!{npcheshenb} can say yes, or {npcheshenb} can say no. $!{npchishernb} disposition might allow you to remedy the situation, or it might not. Do you trust your own judgment enough to take that risk? Are you strong enough to accept the consequences if your gamble goes awry?

And if there is a gosub, would it go into a separate .txt file, or can I tack it on at the end of startup?

Thanks.

2 Likes

If you use *gosub it must be on the same text file other wise you use;
*gosub_scene (scene/text_file_name) (label_name)
Otherwise I think this would work.

Make sure however that you have a *goto Between the *rand and the *label’s to continue to the rest of the story.

There’s no reason to use a subroutine here. Simply put it all in a single *if/*elseif group:

*create npc_heshe ""
*create rand_1
*rand rand_1 1 3
*if rand_1 = 1
    *set npc_heshe "he"
    *goto next_part
*elseif rand_1 = 2
    *set npc_heshe "she"
    ...

But other than that, yea, you more or less seem to understand it.

And basically everything that @Kelvin said is also correct.

Code looks good to me. Except for the *create variable 1. That should probably be without the 1. I’m not sure if quicktest/randomtest will like that though (in startup.txt). When I used the *rand command I had the “variable” as a temp at the top of the page where I later ran the *rand variable.

I’m not really sure why you need the go sub when you could have all the *set commands under the variable. e.g.
in startup.txt

*create npcheshenb ""
*create npchishernb ""

Top of the page where the *rand command will later be used.

*temp variable 

You could probably have this at the top of the page or where ever you want before the body of text uses the gendered code.

*rand variable 1 3
*if (variable = 1)
    *set npcheshenb "he"
    *set npchishernb “his”

*elseif (variable = 2)
    *set npcheshenb “she"
    *set npchishernb “her’"    		
    
*elseif (variable = 3)
    *set npcheshenb “the boss"
    *set npchishernb “the boss’"

Then continue on with your text.


Your go sub can be anywhere in your page but preferably where it wont run into your text again. You don’t want your work to be caught in a loop, or creating unnecessary bugs. You shouldn’t need a *gosub_scene for what you want to create. Unless you want to keep it all separate. Like, one whole page for all the *rand commands to set the genders and then pop back to your story.

Here is some info on using the *rand command


AH! I got ninja’d to it :smiley:

1 Like

@Kelvin, @Reaperoa, @Silverstone Thanks again.

1 Like