Defining NPCs by PC Character Inputs

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
jedishywalker
Newbie
Posts: 2
Joined: Mon Jan 23, 2023 11:12 am
Tumblr: jedishywalker
Contact:

Defining NPCs by PC Character Inputs

#1 Post by jedishywalker »

Hi all!

I'm a first time creator and am working on a project that begins by collecting information about the PC including name, player gender identity, and player romantic interest gender(s). I am trying to use this information to determine the NPCs that exist in game.

Here is the script for that, which seems to be working at this point:

Code: Select all

#The game starts here.

label playerinfo:

    scene bgrainbowstars

    centered "Welcome to {b}SUMMONS{/b}! Before we start, we need a little more information about you."

    $ player_name = renpy.input("First, what would you like to be called?", default='Your Name Here')

    centered "Great, [player_name], it's nice to meet you!\nNext, how do you identify your gender"
    menu:
        "Male":
            $ playergender = "male"
        "Female":
            $ playergender = "female"
        "Both":
            $ playergender = "both"
        "Neither":
            $ playergender = "neither"

    "Thanks! Now, please let us know your type!"
    menu:
        "Guys":
            $ playerinterest = "guys"
        "Girls":
            $ playerinterest = "girls"
        "Both":
            $ playerinterest = "both"
        "Neither":
            $ playerinterest = "neither"

    centered "Great! Let's make sure we've got it right..."

    centered "Your name is {b}[player_name]{/b} and your gender identity is {b}[playergender]{/b}.\nWhen it comes to dating, your type is {b}[playerinterest]{/b}.\nDid we get that right?"
    menu:
        "Yes":
            jump intro
        "No":
            call playerinfo
I have seven character types, each with a male/female variant depending on the above PC selections. Ideally, I'd like to be able to use a master define for the character [bully, jock, nerd, perfect, crush, cool, rich] to keep the main script clean, and then have the game determine which character attributes to pull based on the PC's gender and interest. I am getting this error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/scripts/introduction.rpy", line 27, in script
    bully "What are you doing, [player_name]?\nLooking for something better than that poverty lunch you brought?"
Exception: Sayer 'bully' is not defined.

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/scripts/introduction.rpy", line 27, in script
    bully "What are you doing, [player_name]?\nLooking for something better than that poverty lunch you brought?"
  File "C:\Program Files\renpy-8.0.3-sdk\renpy\ast.py", line 881, in execute
    who = eval_who(self.who, self.who_fast)
  File "C:\Program Files\renpy-8.0.3-sdk\renpy\ast.py", line 774, in eval_who
    raise Exception("Sayer '%s' is not defined." % who)
Exception: Sayer 'bully' is not defined.

Windows-10-10.0.22621 AMD64
Ren'Py 8.0.3.22090809
Summons 1.0
Mon Jan 23 10:30:52 2023
I'm probably structuring the conditions/variables incorrectly, but I'm not sure where. Any help would be appreciated!

Code: Select all

 This file contains the character information for all NPCS in the game.

# Sample Ren'py code: define e = Character("Eileen")

#School Characters

label mainnpcs:
define bullym = Character("Connor", color="#f60101", npcgender = "male")
define bullyf = Character("Samantha", color="#f60101", npcgender = "female")
define jockm = Character("Nick", color="#0d66ee", npcgender = "male")
define jockf = Character("Taylor", color="#0d66ee", npcgender = "female")
define coolm = Character("Dylan", color="#ff9eff", npcgender = "male")
define coolf = Character("Tori", color="#ff9eff", npcgender = "female")
define crushm = Character("Caleb", color="#bc1add", npcgender = "male")
define crushf = Character("Brooke", color="#bc1add", npcgender = "female")
define perfectm = Character("William", color="#3bd006", npcgender = "male")
define perfectf = Character("Ashley", color="#3bd006", npcgender = "female")
define richm = Character("Cameron", color="#ff9eff", npcgender = "male")
define richf = Character("Madison", color="#ff9eff", npcgender = "female")
define nerdm = Character("Thomas", color="#f66b00", npcgender = "male")
define nerdf = Character("Hannah", color="#f66b00", npcgender = "female")

#Summons
label summons:
define lion1 = Character("Ata", color="#f60101", gender = "male")
define lion2 = Character("Atan", color="#f60101", gender = "male")
define lion3 = Character("Satan", color="#f60101", gender = "male")
define snail1 = Character("Phe", color="#f66b00", gender = "female")
define snail2 = Character("Belphe", color="#f66b00", gender = "female")
define snail3 = Character("Belphegor", color="#f66b00", gender = "female")
define toad1 = Character("Mam", color="#dff9eff", gender = "female")
define toad2 = Character("Mammo", color="#ff9eff", gender = "female")
define toad3 = Character("Mammon", color="#ff9eff", gender = "female")
define snake1 = Character("Zeb", color="#3bd006", gender = "female")
define snake2 = Character("Elzebu", color="#3bd006", gender = "female")
define snake3 = Character("Beelzebub", color="#3bd006", gender = "female")
define peacock1 = Character("Cif", color="#0d66ee", gender = "male")
define peacock2 = Character("Cifer", color="#0d66ee", gender = "male")
define peacock3 = Character("Lucifer", color="#0d66ee", gender = "male")
define goat1 = Character("Smo", color="#bc1add", gender = "male")
define goat2 = Character("Smode", color="#bc1add", gender = "male")
define goat3 = Character("Asmodeus", color="#bc1add", gender = "male")
define pig1 = Character("Ado", color="#ff9eff", gender = "neither")
define pig2 = Character("Badon", color="#ff9eff", gender = "neither")
define pig3 = Character("Abadon", color="#ff9eff", gender = "neither")

#Other Characters
label othernpcs:
define mib = Character("Man in Black", color="#000000", gender = "male")

label pronounassign:
# Pronoun If/Elif
    if  npcgender = "male":
        $ he = "he"
        $ him = "him"
        $ his= "his"
    elif npcgender = "female":
        $ he = "she"
        $ him = "her"
        $ his = "hers"
    else:
        $ he = "they"
        $ his = "their"
        $ his = "theirs"

label npcassign:
# NPC If/Elif for Bully, Cool, Jock, Nerd, and Rich NPCS based on PC Gender.
    if playergender = "male":
        $ bully = "bullym"
        $ cool = "coolm"
        $ jock = "jockm"
        $ nerd = "nerdf"
        $ rich = "richf"
    if playergender = "female":
        $ bully = "bullyf"
        $ cool = "coolf"
        $ jock = "jockf"
        $ nerd = "nerdm"
        $ rich = "richm"
    if playergender = "both":
        $ bully = "bullyf"
        $ cool = "coolm"
        $ jock = "jockf"
        $ nerd = "nerdm"
        $ rich = "richf"
    else:
        $ bully = "bullym"
        $ cool = "coolf"
        $ jock = "jockm"
        $ nerd = "nerdf"
        $ rich = "richm"

label romanceassign:
# NPC If/Elif for Bully, Cool, Jock, Nerd, and Rich NPCS based on PC Gender.
    if playerinterest = "guys":
        $ crush = "crushm"
        $ perfect = "perfectm"
    if playerinterest = "girls":
        $ crush = "crushf"
        $ perfect = "perfectf"
    if playerinterest = "both":
        $ crush = "crushm"
        $ perfect = "perfectf"
    else:
        $ crush = "crushf"
        $ perfect = "perfectm"

label variables:
# Running list of all variables used in this section.
        $ playergender = [male, female, neither, both]
        $ npcgender = [male, female, neither, both]
        $ pronouns = [he, him, his]
        $ interest = [guys, girls, both, neither]
        $ schoolnpcs = [bully, jock, nerd, perfect, crush, cool, rich]

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Defining NPCs by PC Character Inputs

#2 Post by rayminator »

you would need to do something like this to input a character name

Code: Select all

define pov = Character("[povname]")

python:
    povname = renpy.input("What is your name?", length=32)
    povname = povname.strip()

    if not povname:
         povname = "Pat Smith"

pov "My name is [povname]!"

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Defining NPCs by PC Character Inputs

#3 Post by _ticlock_ »

jedishywalker wrote: Mon Jan 23, 2023 11:37 am

Code: Select all

Exception: Sayer 'bully' is not defined.
I briefly looked through your post.

I can see you have the following assignment:

Code: Select all

$ bully = "bullym"
Based on the error, you didn't assign the variable bully to any character at the point where the statement of error occurs.

Also, I don't see any return statements in your labels. Possibly, you didn't visit these labels at all.
Do you call label npcassign? What is the sequence of your labels, or how do you access them?

PS: definition of the characters should be outside any labels:

Code: Select all

define bullym = Character("Connor", color="#f60101", npcgender = "male")

label start:
    ...

jedishywalker
Newbie
Posts: 2
Joined: Mon Jan 23, 2023 11:12 am
Tumblr: jedishywalker
Contact:

Re: Defining NPCs by PC Character Inputs

#4 Post by jedishywalker »

Hi! Thanks so much!

First, I totally forgot my returns, so I added them in. ((:X))

I am working through the initial scene after player information collection (intro.rpy):

Code: Select all

# This file contains the script for the introduction to the game.

label intro:

    hide bgrainbowstars 
    with dissolve
    show bgblack

    "Another amazing day at school..." 

    "NOT!"

    "That's usually the norm for me."

    "But today, things hit a new low..."

    hide bgblack 
    with dissolve
    show bgcafea

    "I was minding my own business."
    
    "Just emptying my half-eaten bagged lunch into the garbage when..."

   [color=#FF0000] call npcemote

    show bullysmirk at right

    call npcassign

    bully "What are you doing, [player_name]?\nLooking for something better than that poverty lunch you brought?"

    call npcassign 
    
    bully "Why don't you let me help you?"[/color]
    
    "THUD" with vpunch 
The red section is where I am trying to have the alternate variables come into play.

I have a separate tab called characters with the script below:

Code: Select all

# This file contains the character imformation for all NPCS in the game.

# Sample Ren'py code: define e = Character("Eileen")

#School Characters
define bullym = Character("Connor", color="#f60101", npcgender = "male")
define bullyf = Character("Samantha", color="#f60101", npcgender = "female")
define jockm = Character("Nick", color="#0d66ee", npcgender = "male")
define jockf = Character("Taylor", color="#0d66ee", npcgender = "female")
define coolm = Character("Dylan", color="#ff9eff", npcgender = "male")
define coolf = Character("Tori", color="#ff9eff", npcgender = "female")
define crushm = Character("Caleb", color="#bc1add", npcgender = "male")
define crushf = Character("Brooke", color="#bc1add", npcgender = "female")
define perfectm = Character("William", color="#3bd006", npcgender = "male")
define perfectf = Character("Ashley", color="#3bd006", npcgender = "female")
define richm = Character("Cameron", color="#ff9eff", npcgender = "male")
define richf = Character("Madison", color="#ff9eff", npcgender = "female")
define nerdm = Character("Thomas", color="#f66b00", npcgender = "male")
define nerdf = Character("Hannah", color="#f66b00", npcgender = "female")

#Summons
define lion1 = Character("Ata", color="#f60101", gender = "male")
define lion2 = Character("Atan", color="#f60101", gender = "male")
define lion3 = Character("Satan", color="#f60101", gender = "male")
define snail1 = Character("Phe", color="#f66b00", gender = "female")
define snail2 = Character("Belphe", color="#f66b00", gender = "female")
define snail3 = Character("Belphegor", color="#f66b00", gender = "female")
define toad1 = Character("Mam", color="#dff9eff", gender = "female")
define toad2 = Character("Mammo", color="#ff9eff", gender = "female")
define toad3 = Character("Mammon", color="#ff9eff", gender = "female")
define snake1 = Character("Zeb", color="#3bd006", gender = "female")
define snake2 = Character("Elzebu", color="#3bd006", gender = "female")
define snake3 = Character("Beelzebub", color="#3bd006", gender = "female")
define peacock1 = Character("Cif", color="#0d66ee", gender = "male")
define peacock2 = Character("Cifer", color="#0d66ee", gender = "male")
define peacock3 = Character("Lucifer", color="#0d66ee", gender = "male")
define goat1 = Character("Smo", color="#bc1add", gender = "male")
define goat2 = Character("Smode", color="#bc1add", gender = "male")
define goat3 = Character("Asmodeus", color="#bc1add", gender = "male")
define pig1 = Character("Ado", color="#ff9eff", gender = "neither")
define pig2 = Character("Badon", color="#ff9eff", gender = "neither")
define pig3 = Character("Abadon", color="#ff9eff", gender = "neither")

#Other Characters
define mib = Character("Man in Black", color="#000000", gender = "male")

label variables:
# Running list of all variables used in this section.
#Player Info
$ playergender = [male, female, neither, both]
$ npcgender = [male, female, neither, both]
$ pronouns = [he, him, his]
$ playerinterest = [guys, girls, both, neither]
#Characters
$ schoolnpcs = [bully, jock, nerd, perfect, crush, cool, rich]
$ bully = [bullym, bullyf]
$ jock = [jockm, jockf]
$ nerd = [nerdm, nerdf]
$ perfect = [perfectm, perfectf]
$ crush = [crushm, crushf]
$ cool = [coolm, coolf]
$ rich = [richm, richf]
#Emotions
#Bully
$ bullyangry = [bullymangry, bullyfangry]
$ bullyblush = [bullymblush, bullyfblush]
$ bullyconfuse = [bullymconfuse, bullyfconfuse]
$ bullyhappy = [bullymhappy, bullyfhappy]
$ bullylaugh = [bullymlaugh, bullyflaugh]
$ bullynervous = [bullymnervous, bullyfnervous]
$ bullysad = [bullymsad, bullyfsad]
$ bullyscare = [bullymscare, bullyfscare]
$ bullysmirk = [bullymsmirk, bullyfsmirk]
$ bullysurprise = [bullymsurprise, bullyfsurprise]
$ bullywink = [bullymwink, bullyfwink]
#Jock
$ jockangry = [jockmangry, jockfangry]
$ jockblush = [jockmblush, jockfblush]
$ jockconfuse = [jockmconfuse, jockfconfuse]
$ jockhappy = [jockmhappy, jockfhappy]
$ jocklaugh = [jockmlaugh, jockflaugh]
$ jocknervous = [jockmnervous, jockfnervous]
$ jocksad = [jockmsad, jockfsad]
$ jockscare = [jockmscare, jockfscare]
$ jocksmirk = [jockmsmirk, jockfsmirk]
$ jocksurprise = [jockmsurprise, jockfsurprise]
$ jockwink = [jockmwink, jockfwink]
#Nerd
$ nerdangry = [nerdmangry, nerdfangry]
$ nerdblush = [nerdmblush, nerdfblush]
$ nerdconfuse = [nerdmconfuse, nerdfconfuse]
$ nerdhappy = [nerdmhappy, nerdfhappy]
$ nerdlaugh = [nerdmlaugh, nerdflaugh]
$ nerdnervous = [nerdmnervous, nerdfnervous]
$ nerdsad = [nerdmsad, nerdfsad]
$ nerdscare = [nerdmscare, nerdfscare]
$ nerdsmirk = [nerdmsmirk, nerdfsmirk]
$ nerdsurprise = [nerdmsurprise, nerdfsurprise]
$ nerdwink = [nerdmwink, nerdfwink]
#Perfect
$ perfectangry = [perfectmangry, perfectfangry]
$ perfectblush = [perfectmblush, perfectfblush]
$ perfectconfuse = [perfectmconfuse, perfectfconfuse]
$ perfecthappy = [perfectmhappy, perfectfhappy]
$ perfectlaugh = [perfectmlaugh, perfectflaugh]
$ perfectnervous = [perfectmnervous, perfectfnervous]
$ perfectsad = [perfectmsad, perfectfsad]
$ perfectscare = [perfectmscare, perfectfscare]
$ perfectsmirk = [perfectmsmirk, perfectfsmirk]
$ perfectsurprise = [perfectmsurprise, perfectfsurprise]
$ perfectwink = [perfectmwink, perfectfwink]
#Crush
$ crushangry = [crushmangry, crushfangry]
$ crushblush = [crushmblush, crushfblush]
$ crushconfuse = [crushmconfuse, crushfconfuse]
$ crushhappy = [crushmhappy, crushfhappy]
$ crushlaugh = [crushmlaugh, crushflaugh]
$ crushnervous = [crushmnervous, crushfnervous]
$ bcrushsad = [crushmsad, crushfsad]
$ crushscare = [crushmscare, crushfscare]
$ crushsmirk = [crushmsmirk, crushfsmirk]
$ crushsurprise = [crushmsurprise, crushfsurprise]
$ crushwink = [crushmwink, crushfwink]
#Cool
$ coolangry = [coolmangry, coolfangry]
$ coolblush = [coolmblush, coolfblush]
$ coolconfuse = [coolmconfuse, coolfconfuse]
$ coolhappy = [coolmhappy, coolfhappy]
$ coollaugh = [coolmlaugh, coolflaugh]
$ coolnervous = [coolmnervous, coolfnervous]
$ coolsad = [coolmsad, coolfsad]
$ coolscare = [coolmscare, coolfscare]
$ coolsmirk = [coolmsmirk, coolfsmirk]
$ coolsurprise = [coolmsurprise, coolfsurprise]
$ coolwink = [coolmwink, coolfwink]
#Rich
$ richangry = [richmangry, richfangry]
$ richblush = [richmblush, richfblush]
$ richconfuse = [richmconfuse, richfconfuse]
$ richhappy = [richmhappy, richfhappy]
$ richlaugh = [richmlaugh, richflaugh]
$ richnervous = [richmnervous, richfnervous]
$ richsad = [richmsad, richfsad]
$ richscare = [richmscare, richfscare]
$ richsmirk = [richmsmirk, richfsmirk]
$ richsurprise = [richmsurprise, richfsurprise]
$ richwink = [richmwink, richfwink]
return

# Pronoun If/Elif
label pronounassign:

if npcgender == "male":
    $ he = "he"
    $ him = "him"
    $ his= "his"
elif npcgender == "female":
    $ he = "she"
    $ him = "her"
    $ his = "hers"
else:
    $ he = "they"
    $ his = "their"
    $ his = "theirs"
return

# NPC If/Elif for Bully, Cool, Jock, Nerd, and Rich NPCS based on PC Gender.
label npcassign:

if playergender == "male":
    $ bully = "bullym"
    $ cool = "coolm"
    $ jock = "jockm"
    $ nerd = "nerdf"
    $ rich = "richf"
elif playergender == "female":
    $ bully = "bullyf"
    $ cool = "coolf"
    $ jock = "jockf"
    $ nerd = "nerdm"
    $ rich = "richm"
elif playergender == "both":
    $ bully = "bullyf"
    $ cool = "coolm"
    $ jock = "jockf"
    $ nerd = "nerdm"
    $ rich = "richf"
else:
    $ bully = "bullym"
    $ cool = "coolf"
    $ jock = "jockm"
    $ nerd = "nerdf"
    $ rich = "richm"
return
The game is now returning the right gender for the NPC based on PC gender, but the name is still showing as 'bullyf'. I'm also not able to display the images I need, but I think if I can fix this problem, that one will be a similar fix.

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Defining NPCs by PC Character Inputs

#5 Post by _ticlock_ »

jedishywalker wrote: Mon Jan 23, 2023 4:03 pm

Code: Select all

$ bully = "bullym"
I didn't catch it the first time. You should do:

Code: Select all

$ bully = bullym

User avatar
ThrashNeon
Newbie
Posts: 22
Joined: Thu Dec 28, 2017 8:21 am
Contact:

Re: Defining NPCs by PC Character Inputs

#6 Post by ThrashNeon »

jedishywalker wrote: Mon Jan 23, 2023 4:03 pm The game is now returning the right gender for the NPC based on PC gender, but the name is still showing as 'bullyf'. I'm also not able to display the images I need, but I think if I can fix this problem, that one will be a similar fix.
In order to display the player's chosen name, you need to change your character defs to something like this:

Code: Select all

default player_name = "Pat" # or whatever

define bullym = Character("[player_name]", color="#f60101", npcgender = "male")
define bullyf = Character("[player_name]", color="#f60101", npcgender = "female")
# etc...


Post Reply

Who is online

Users browsing this forum: Google [Bot], Loneclaw, Ocelot