Custom Player
Author: NingNing
Last update:2022-06-05
This tutorial is about customizing character/ player, so let's start customizing a character from scratch!
First, let's let the player enter their name
Let player customize their names
- I have already done a tutorial on this topic, which can be found on my blog - Space Of NingNing
Of course I'll be writing here again so you can continue reading here too!
So let's create a character first
default pn = Character("[player_name]")
- The words inside 2
""
will be the character's name
Let's create a label
label playerA_name:
After the label
is created, let's ask the player what name they want to use!
python:
player_name = renpy.input("What's your name?", length=10)
player_name = player_name.strip()
if not player_name:
player_name = "Hero"
- 1st sentence -
player_name = renpy.input("What's your name?", length=10)
- The words in the
""
ofrenpy.input("")
will be displayed on the screen for asking questions, and can be modified as you wish ((It is also possible to not ask questions - The number after
length=
means that the player can enter how many characters. If it is not written, it means that the player can enter an unlimited number of characters.
- The words in the
if not player_name:
- if the player did not enter anythingplayer_name = "Hero"
- the player's name will become the default - Hero -
Now let's check if the code works successfully!
"Saved!"
"Your name is [player_name]"
As long as the word displayed after - your name is - is the word you just entered, it means that the text is saved successfully.
Let the player choose a name
The difference from the above is that now we want the player to choose a name instead of typing a name
Here we are going to use menu
, those who need to review can click here to enter the menu
tutorial
To let the player choose a name you can use code like this:
First, change the code from default pn = Character("[player_name]")
-> to default pn = Character("")
Then after label start
type:
"Choose your name"
menu:
"Alex":
$ pn = Character("Alex")
jump label2
"Bill":
$ pn = Character("Bill")
jump label2
Make sure the name is displayed correctly
label label2:
pn "So this is my name!"
e "[pn] hello~"
- You can replace Alex and Xiao Ming with other names you want or add more options
- The above code is just an example, you can change it at will!
Prevent players from entering specific names
There are times when you may want to avoid players using specific names, and this can be achive in Renpy
You can use code like this:
python:
player_name_valid = False
banned = ["Adam", "Bella", "Cindy", "Dog"]
while not player_name_valid:
player_name = renpy.input("What's your name?")
player_name = player_name.strip()
if player_name.lower() in banned:
narrator("You can't use this name!", interact=True)
else:
player_name_valid = True
if not player_name:
player_name = "Hero"
- The words defined after
banned = [
are banned words. When the player enters - "Adam", "Bella", "Cindy", "Dog" -, the system will show you - You can't use this name!- Then ask the player to re-enter the name - If the player does not enter any name, the default name is - Hero -
Let the player choose the font color
Let players choose the color that appears when their name is displayed!
Here we use menu
, those who need to review can click [here](http://localhost:3000/docs/%E5%9F%BA%E6%9C%AC/create-choices#%E5%BB %BA%E7%AB%8B%E7%AC%AC%E4%B8%80%E5%80%8B%E5%88%86%E6%94%AF) enter the tutorial of menu
"Choose a color you want to use!"
menu:
"purple":
$ pn = Character("[player_name]", color="#720b98", what_color="#720b98")
"blue":
$ pn = Character("[player_name]", color="#73a9c2", what_color="#73a9c2")
Let's check if it works!
pn "This is my color!"
```
![image alt](https://wningningw.notion.site/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fa2357b27-4b46-4d19-b43f-e6311f01212a%2FUntitled.png?table=block&id=73234cf5-7ad6-4aa2-9dbd-fc52cea0ab8a&spaceId=a18de6f9-6c26-4b46-8b4c-2584bf86ed47&width=2000&userId=&cache=v2)
## Change player name style
Basically have to change in the beginning of the define sentence
#### Default color
- color="#color code"
Example:
define n = Character("NingNing", color="#000000")
#### Underline Name
- who_underline=True
Example:
define n = Character("NingNing", who_underline=True)
- If you want to turn off the state of underline, change `True` to `False`
#### Frame / Outline Name
- who_outlines=[(outline size, "#colorcode")])
Example:
define n = Character("NingNing", who_outlines=[(1, "#ffffff")]))
#### Bold Name
- who_bold=True
Example:
define n = Character("NingNing", who_bold=True)
- If you want to turn off the bold state, change `True` to `False`
#### Italic Name
- who_italic=True
Example:
define n = Character("NingNing", who_italic=True)
- If you want to turn off the italic state, change `True` to `False`
#### Change name font
- what_font="font storage path"
Example:
```
define n = Character("NingNing", what_font="SourceHanSerif_TW.ttf")
```
## Character Pet Phrase
- Maybe you want the character to keep saying the same thing at the end or at the beginning (like a pet phrase) you can use the following code:
- what_prefix=''
- what_suffix=''
Example:
```
define n = Character("NingNing", what_prefix='wow', what_suffix='yeah')
```
## Define character gender
- Allow the player to choose gender, so that later when encountering to use "he" or "her" or something like that, it will be changed automatically according to the gender selected by the player
So first we need to define a few variables before `label start`
```
default gender_call = "She"
default adresse = "Mrs."
```
- Like above we define 2 variables
- The first gender_call is the pronoun of the character, if it's a girl it's "she"
- The second adresse is the character's title, if it's a girl, it's "Mrs."
Now we're going to let the player choose their gender
```
menu:
"What is your gender?"
"girl":
$ gender_call = "her"
$ adresse = "Mrs."
"boy":
$ gender_call = "He"
$ adresse = "Mr."
```
- This paragraph should be placed after `label start`
- If you choose a girl, it will be the same as the default setting
- If you choose a boy, the pronoun will be changed to "He" and the title will be changed to "Mr."
Preview: https://www.youtube.com/watch?v=d1tD7kVHHyo
---
This post is over now~
You can give me / my website a clap if this help you!
My website --> https://spaceofningningen.blogspot.com/
![Image Alt](https://wningningw.notion.site/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F727f550d-eadf-4a6f-9f03-790e39aacf16%2FUntitled.png?table=block&id=74f18692-17b6-45a2-b56d-c67465bd148e&spaceId=a18de6f9-6c26-4b46-8b4c-2584bf86ed47&width=2000&userId=&cache=v2)
Thank you for your support~