Name Input restrictions

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
Roselia-Thorns
Regular
Posts: 27
Joined: Tue Sep 13, 2016 10:01 pm
Projects: Undertale: Kissy Cutie
Tumblr: roseradetea
itch: roseradetea
Contact:

Name Input restrictions

#1 Post by Roselia-Thorns »

So at the beggining of my game you have to enter your name.
Is there a way to prevent people from writting certain names?
If they writte the name of one of the characters it creates a total confussion on the story.

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Name Input restrictions

#2 Post by Milkymalk »

Easy.

Code: Select all

label entername:
    # enter name here
    if name in [charactername1, charactername2, ... ]:
        "Another charakter already has this name. Please choose another."
        jump entername
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
Roselia-Thorns
Regular
Posts: 27
Joined: Tue Sep 13, 2016 10:01 pm
Projects: Undertale: Kissy Cutie
Tumblr: roseradetea
itch: roseradetea
Contact:

Re: Name Input restrictions

#3 Post by Roselia-Thorns »

I got this error

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 424, in script
    python:
  File "game/script.rpy", line 429, in <module>
    if povname in [Chara]:
NameError: name 'Chara' is not defined

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

Full traceback:
  File "game/script.rpy", line 424, in script
    python:
  File "C:\Users\cabal_000\Desktop\renpy\renpy\ast.py", line 814, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\cabal_000\Desktop\renpy\renpy\python.py", line 1695, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/script.rpy", line 429, in <module>
    if povname in [Chara]:
NameError: name 'Chara' is not defined
this is my code

Code: Select all

label entername:
python:
   povname = renpy.input("How should I call you?", exclude='{}#$%&?¡¿')
   povname = povname.strip()
   if not povname:
         povname = "Toby"
   if povname in [Chara, Frisk, Sans, Papyrus]:
        "That's not your name"
        jump entername
I'm very noob sorry

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Name Input restrictions

#4 Post by Milkymalk »

You have to put the names in quotes:
["Chara", "Frisk", "Sans", "Papyrus"]
Also, "jump" can not used inside a Python block.

You are obviously not used to Python or coding in general. If you expect to do anything more than VERY basic Ren'Py stuff, I suggest you read a beginner's guide to Python before you proceed. It's easy stuff, you just need to know it. The same goes for Ren'Py script language: You can't mix it with Python. There are Python equivalents for most Ren'Py statements though, but it's alyways easier to use the script language itself unless you absolutely can't.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
Roselia-Thorns
Regular
Posts: 27
Joined: Tue Sep 13, 2016 10:01 pm
Projects: Undertale: Kissy Cutie
Tumblr: roseradetea
itch: roseradetea
Contact:

Re: Name Input restrictions

#5 Post by Roselia-Thorns »

Ok, thanks! Now I understand my problem!
It worked.

Post Reply

Who is online

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