Custom Name 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
InsanePenguin
Newbie
Posts: 6
Joined: Tue Apr 24, 2018 1:55 pm
Contact:

Custom Name error

#1 Post by InsanePenguin »

Hello, im trying to have the players in my game have the option to name their character unless they want to. please advise on the following code

# People
define m = Character("Mia")
define a = Character("Allison")
define k = Character("Kira")
define v = Character("Veronica")
define x = Character("[player_name]")

# The game starts here.

label start:
scene black
"Would you like to choose your name?"
menu:
"Yes":
jump choosename
return
"No":
jump introscene
return

label choosename:
scene black
$ player_name = renpy.input ("What is your name?")
$ player_name = player_name.strip()
if player_name == "":
$ player_name ="Adam"


label introscene:

scene misa

m "Pleased to meet you, %(player_name)s"

x "Got a name!!"

m "This is a test"

the game picks up the custom name that the player inputs but I get an error if they choose no in the options

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Custom Name error

#2 Post by kivik »

That because if they skip, the player_name variable is not declared at all.

Add this in your code just after the characters and it'll fix it:

Code: Select all

default player_name = "Adam"
You can also remove the line

Code: Select all

$ player_name = "Adam"

InsanePenguin
Newbie
Posts: 6
Joined: Tue Apr 24, 2018 1:55 pm
Contact:

Re: Custom Name error

#3 Post by InsanePenguin »

It worked!! thank you so much

Post Reply

Who is online

Users browsing this forum: MSN [Bot]