[SOLVED] Forbid NPC Name for Player Name Input

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
Eirrir
Regular
Posts: 81
Joined: Mon Feb 27, 2017 7:16 pm
Projects: Operation: Future Domination
Tumblr: Eirrir
itch: eirrir
Contact:

[SOLVED] Forbid NPC Name for Player Name Input

#1 Post by Eirrir »

Hi all,

I currently have set up a way for players to input their character name, but I'm wondering if there's a way to forbid the players from inputting NPC names.

Code: Select all

label input_name:
    if persistent.player is None:
        $ player = renpy.input("", "Bob")
        $ player = player.strip()
        $ persistent.player = player
For instance, I do not want the player to input the name of an NPC called "Dave." If the player does input that name, I would like there to be some text or window saying "Please choose a different name" and then return the player to inputting their character name. Any help to achieve this would be very much appreciated!
Last edited by Eirrir on Wed Jun 14, 2017 8:57 pm, edited 1 time in total.
Current VN Project:
Image
Game Development Blog

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Forbid NPC Name for Player Name Input

#2 Post by Imperf3kt »

Thats probably going to upset a lot of people.
Imagine a game restricting you from using your own name, I sure know it'd really piss me off.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Forbid NPC Name for Player Name Input

#3 Post by trooper6 »

Are you sure you want persistent here? persistent is to save data between different playthroughs. So I play through your game and call myself Bob. Finish the game it is fun and I'm done. Then my friend Tina decides she wants to play the game on my computer and so she starts a new game...guess what? Because you used persistent data, she is also going to be called Bob. I suspect you just want regular data, not persistent data.

But let's say you want regular data, not persistent data, do something like this (and remember to declare your variables using default):

Code: Select all

default player = None
default npcs = ["Dave", "Jane", "Jess"]

label start:
    "You game starts here."
    call set_name

    "Now we can continue on with the game."
    "Blah blah..."

label set_name:
    if player == None:
        "What is your name?"
        $player = renpy.input("", "Bob")
        $player = player.strip()
    elif player in npcs:
        "You can't use that name, try again."
        $player = None
    else:
        return
    jump set_name 
    
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Eirrir
Regular
Posts: 81
Joined: Mon Feb 27, 2017 7:16 pm
Projects: Operation: Future Domination
Tumblr: Eirrir
itch: eirrir
Contact:

Re: Forbid NPC Name for Player Name Input

#4 Post by Eirrir »

Imperf3kt wrote:Thats probably going to upset a lot of people.
Imagine a game restricting you from using your own name, I sure know it'd really piss me off.
Thanks for your input. I'm sure it may bother some people that they won't be able to use their ideal name, but hopefully, I will be saving them a lot of confusion with names and NPCs when they're playing the game.
Current VN Project:
Image
Game Development Blog

User avatar
Eirrir
Regular
Posts: 81
Joined: Mon Feb 27, 2017 7:16 pm
Projects: Operation: Future Domination
Tumblr: Eirrir
itch: eirrir
Contact:

Re: Forbid NPC Name for Player Name Input

#5 Post by Eirrir »

trooper6 wrote:Are you sure you want persistent here? persistent is to save data between different playthroughs. So I play through your game and call myself Bob. Finish the game it is fun and I'm done. Then my friend Tina decides she wants to play the game on my computer and so she starts a new game...guess what? Because you used persistent data, she is also going to be called Bob. I suspect you just want regular data, not persistent data.

But let's say you want regular data, not persistent data, do something like this (and remember to declare your variables using default):

Code: Select all

default player = None
default npcs = ["Dave", "Jane", "Jess"]

label start:
    "You game starts here."
    call set_name

    "Now we can continue on with the game."
    "Blah blah..."

label set_name:
    if player == None:
        "What is your name?"
        $player = renpy.input("", "Bob")
        $player = player.strip()
    elif player in npcs:
        "You can't use that name, try again."
        $player = None
    else:
        return
    jump set_name 
    
Thank you for your help, trooper6! It may seem odd, but I intended to have persistent data for plot and replayability purposes. I tried to follow your code set-up with a few tweaks for persistent data, but I couldn't get it to work; inputting any name in npcs is still allowed. Would you mind lending me another hand if it's possible?

Code: Select all

default persistent.player = None
default npcs = ["Dave", "Jane", "Jess"]

label input_name:
    if persistent.player is None:
        $ player = renpy.input("", "Bob")
        $ player = player.strip()
        $ persistent.player = player
    elif persistent.player in npcs:
        "Please choose a different name."
        $ persistent.player = None
        return
    else:
        $ player = persistent.player
Current VN Project:
Image
Game Development Blog

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Forbid NPC Name for Player Name Input

#6 Post by trooper6 »

Persistent variables are not regular variables, so they don't use default, they use define.

Like so:

Code: Select all

define persistent.player = None
default npcs = ["Dave", "Jane", "Jess"]

label start:
    "You game starts here."
    call set_name

    "Now we can continue on with the game."
    "Blah blah..."

label set_name:
    if persistent.player == None:
        "What is your name?"
        $player = renpy.input("", "Bob")
        $player = player.strip()
        if player is not None:
            $persistent.player = player
    elif persistent.player in npcs:
        "You can't use that name, try again."
        $persistent.player = None
    else:
        return
    jump set_name 
But remember, by using persistent variables, the player can never rename their character after the very first time they play the game. Is there a typo? Too Bad, you are stuck with that name even if you start an entirely new game from the beginning. You change your mind and would like to play with a different name the second time you play the game? Too bad. You want to play the game for the first time, but your little sister played it before you? Too bad, you don't get a new name.

I wouldn't do persistent, but hey...that is up to you.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Eirrir
Regular
Posts: 81
Joined: Mon Feb 27, 2017 7:16 pm
Projects: Operation: Future Domination
Tumblr: Eirrir
itch: eirrir
Contact:

Re: Forbid NPC Name for Player Name Input

#7 Post by Eirrir »

Thank you very much for the help! I got it to work successfully :D. This question has been solved.
Current VN Project:
Image
Game Development Blog

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], simple_human