[Solved] Adding Random Name Generator to story syntax error

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
Brandom
Newbie
Posts: 11
Joined: Thu Mar 16, 2017 6:24 pm
Contact:

[Solved] Adding Random Name Generator to story syntax error

#1 Post by Brandom »

I've been trying to mess around with this random name generator and implement it in my game:
viewtopic.php?f=51&t=26368

But instead of one name, I would like it to randomly select three names.
When I try to run the game, it gives me the following error:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 221: invalid syntax
    $ gen.random_names()
     ^
    

Ren'Py Version: Ren'Py 6.99.12.4.2187

Here are the pieces of related code:


Above everything else:

Code: Select all

define mc = DynamicCharacter("mc_name")
define sister = DynamicCharacter("sister_name")
define mom = DynamicCharacter("mom_name")
Inside the 'init' section:

Code: Select all

init:
    
    $ randomize_mc_name = False
    $ randomize_sister_name = False
    $ randomize_mom_name = False

    $ mc_name = ""
    $ sister_name = ""
    $ mom_name = ""
    $ random_mc_name_list = ["Sean", "Tommy", "Dave", "Paul", "Vinnie"]
    $ random_sister_name_list = ["Catherine", "Jenny", "Maggie", "Lauren", "Demi", "Carrie", "Cassie", "Katie", "Emily"]
    $ random_mom_name_list = ["Debbie", "Heather", "Jennifer", "Laurie", "Eva", "Carmen", "Erica", "Jean", "Beatrice"]

Inside the 'init python' section:

Code: Select all

    class GENERATOR:
        
        def random_names(self):
            if (randomize_mc_name):
                generated_mc_name = renpy.random.choice(random_mc_name_list)
                store.mc_name = generated_son_name
            if (randomize_daughter_name):
                generated_sister_name = renpy.random.choice(random_sister_name_list)
                store.sister_name = generated_sister_name
            if (randomize_mom_name):
                generated_mom_name = renpy.random.choice(random_mom_name_list)
                store.mom_name = generated_mom_name

And then 'in the story', I allow players to either enter names they chose themselves or with the help of this 'modification', have them randomly selected. Before I tried this, I used three pre-set names for each character, which worked flawlessly. Here's the section where players can enter their names, or if they skip it, it should continue to the randomizer:

Code: Select all

label changenames:
    $ mc_name = ""
    $ sister_name = ""
    $ mom_name = ""
    
    #
    # Changing the player's name
    #
    $ mc_name = renpy.input("What shall we call you?")
    $ mc_name = mc_name.strip()
    
    if mc_name == "":
        $ mc_name = renpy.input("Please provide a name for the male character:")
        
    if mc_name == "":
        "You did not enter a name. Your name will now be randomly chosen from a pre-determined list."
        $ randomize_mc_name = True
        

    #
    # Changing sister's name
    #
    $ sister_name = renpy.input("What is your sister's name?")
    $ sister_name = sister_name.strip()
    
    if sister_name == "":
        $ sister_name = renpy.input("Please provide a name for the sister character:")
        
    if sister_name == "":
        "You did not enter a name. Your sister's character name will also be randomly selected."
        $ randomize_sister_name = True
    #
    # Changing mom's name
    #
    $ mom_name = renpy.input("What is your mom's name?")
    $ mom_name = mom_name.strip()
    
    if mom_name == "":
        $ mom_name = renpy.input("Please provide a name for the mom character:")
        
    if mom_name == "":
        "You did not enter a name. Her name will be randomly picked as well."
        $ randomize_mom_name = True
The 'randomizer' should be started in the next section - which is in the next label over; didn't add a jump since it's the next label in the code (including the line which gives the syntax error) :

Code: Select all

label confirmnames:
    
    python:
        gen = GENERATOR()
        
        $ gen.random_names()
    
    menu:
        "Confirm the main character names: {b}[mc_name]{/b} (your name), {b}[sister_name]{/b} (your sister) and {b}[mom_name]{/b} (your mom).":
            jump story
        
        "I would like to change the names.":
            jump changenames

I hope I followed the instructions carefully - but I did need to add a few lines to make sure the two extra characters would be able to be randomized as well.
Any help would be appreciated! :)


------------------------------------------------------------------------------------------------------------------

Never mind - I had a total brain fart. The indentation was incorrect - before, I received errors regarding expecting a block, for example, when indentation was incorrect, so I overlooked that entire possibility of indentation mistakes when all it said was 'syntax error'.

When I fixed the indentation, I received a few different errors, which now seem fixed and I'm trying to fix a bug where the sister and mom name are randomized, but not the son name. Still working on that, but the above is solved.

------------------------------------------------------------------------------------------------------------------

Fixed the son's name not being randomized as well - forgot to change one mention of a variable when I altered its name.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]