Choose Player Name - Where to put the code in?

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
User avatar
Otome-Girl
Newbie
Posts: 22
Joined: Mon Feb 10, 2014 5:37 pm
Contact:

Choose Player Name - Where to put the code in?

#1 Post by Otome-Girl »

Hi everybody,

I'm having trouble with the code. I started to write the game and wanted to start with the coding for asking the player for his/her name. I think I pasted it into the wrong lines, it doesn't work. Can you tell me where I failed? :( Sorry for my bad english.

This is my code:

Code: Select all


# You can place the script of your game in this file.


# Here we define the backgrounds that are used.
image bg intro_bg = "Intro_0.png"

# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"

# Declare characters used by this game.
define s = Character('Saki', color="#5F04B4")
define o = Character('Otome', color="#000000")

# The game starts here.

label start:

define player_first_name = ""
define player_last_name = ""
define player_name = ""

"What's your given name?"

 # The phrase in the brackets is the text that the game will display to prompt 
 # the player to enter the name they've chosen.

 $ player_name = renpy.input("What is your given name?") or "Me" #check for no input in name is done here
 $ player_name = player_name.strip() # it may interfere with the splitting code if it strips space chars mid-string, need to check on that. If it's a problem use .rstrip() instead.

 python:
         if player_name == "":
        $ player_name="Shuji" # If the player can't be bothered to choose a name, then we choose a suitable one for them:
    
 # Now the other characters in the game can greet the player.
 "Let's begin the adventure [player_name]!"

    return

Have a nice day!

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Choose Player Name - Where to put the code in?

#2 Post by Asceai »

You need to be careful about the indentation here. Lines that are part of blocks, like "python:", if statements etc. need to be indented deeper than the block and all lines in a block must be indented the same amount.

The two lines that call renpy.input to get the player name

Code: Select all

 $ player_name = renpy.input("What is your given name?") or "Me" #check for no input in name is done here
 $ player_name = player_name.strip() # it may interfere with the splitting code if it strips space chars mid-string, need to check on that. If it's a problem use .rstrip() instead.
are indented one space deeper than other parts.
The $ player_name="Shuji" line also needs to be deeper than the 'if player_name == "":', but it is actually one space shallower. (The $ counts as part of the line)

The other bug stopping this from running is that you have a $ line inside a python: block. $ indicates a line of python, so it is not necessary when in a python: block.

Here is a corrected version:

Code: Select all

# You can place the script of your game in this file.


# Here we define the backgrounds that are used.
image bg intro_bg = "Intro_0.png"

# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"

# Declare characters used by this game.
define s = Character('Saki', color="#5F04B4")
define o = Character('Otome', color="#000000")

# The game starts here.

label start:
    define player_first_name = ""
    define player_last_name = ""
    define player_name = ""

    "What's your given name?"

    # The phrase in the brackets is the text that the game will display to prompt
    # the player to enter the name they've chosen.

    $ player_name = renpy.input("What is your given name?") or "Me" #check for no input in name is done here
    $ player_name = player_name.strip() # it may interfere with the splitting code if it strips space chars mid-string, need to check on that. If it's a problem use .rstrip() instead.

    python:
        if player_name == "":
            player_name="Shuji" # If the player can't be bothered to choose a name, then we choose a suitable one for them:
    # Now the other characters in the game can greet the player.
    "Let's begin the adventure [player_name]!"
The code will run like this, but there's something else you might want to look at:

Code: Select all

$ player_name = renpy.input("What is your given name?") or "Me"
This will already give the player a default name (Me) if the player doesn't enter anything, so the other check later isn't necessary. I'd just put "Shuji" instead of "Me" in that first line and get rid of the whole python block later.

User avatar
Otome-Girl
Newbie
Posts: 22
Joined: Mon Feb 10, 2014 5:37 pm
Contact:

Re: Choose Player Name - Where to put the code in?

#3 Post by Otome-Girl »

Dear Asceai, thank you so much, you helped me a lot! I have to learn a lot from now on about Blocks and indentation! :lol: Have a nice day!!!

User avatar
Otome-Girl
Newbie
Posts: 22
Joined: Mon Feb 10, 2014 5:37 pm
Contact:

Re: Choose Player Name - Where to put the code in?

#4 Post by Otome-Girl »

I've got a little new problem with this… :oops:
Everything works, but when the User wants to write the name, the letters are yellow. And my background is white, so you don't see the letters. I defined a color for the Player already, but it doesn't work. Could someone help me out here? :(

Code: Select all

define o = Character('[player_name]', color="#000000", show_two_window=True)

Code: Select all

 $ player_name = renpy.input("Wie heißt du?") or "Otome" #check for no input in name is done here
    $ player_name = player_name.strip() # it may interfere with the splitting code if it strips space chars mid-string, need to check on that. If it's a problem use .rstrip() instead.
Later in the game, everything works. It's only this problem at this point.
Attachments
name.png
name.png (33.88 KiB) Viewed 3343 times
Image

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Choose Player Name - Where to put the code in?

#5 Post by Asceai »

$style.input.color = "#000"

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Choose Player Name - Where to put the code in?

#6 Post by philat »

Put this in a python block somewhere:

Code: Select all

style.input_text.color = "#000"

User avatar
Otome-Girl
Newbie
Posts: 22
Joined: Mon Feb 10, 2014 5:37 pm
Contact:

Re: Choose Player Name - Where to put the code in?

#7 Post by Otome-Girl »

Thank you so much!! :D It worked!! Thanx!!
Image

Post Reply

Who is online

Users browsing this forum: MisterPinetree