What this does is handling MC's name with a couple handy features:
- can be given a list of names (NPCs) to avoid!
- name is persistent (game remembers it even if you start a new game, so it will also be remembered in replays!)
- asked once on first playthrough, but changable from Preferences anytime (could even be set before first playthrough)
Code: Select all
## in script.rpy
default npcs = ["name1","name2","name3"] ## list of names
define mc = Character("[persistent.mcname]", color="#faa")
## ...
label start:
if not persistent.mcname: ## only asks for a name if none is defined. you can remove the condition if you prefer
call screen name_mc
mc "Hi! My name is [persistent.mcname]."
Code: Select all
## screens.rpy
screen name_mc():
modal True
zorder 100
default name = persistent.mcname or "Mary Sue" ## put your own default name here
add "overlay.png"
frame:
xalign 0.5
yalign 0.5
hbox:
spacing 20
add "mc sprite": ## optional, show the character they are supposed to name
zoom 0.5
xalign 0.0
yalign 1.0
vbox:
ypos 100
xalign 0.5
spacing 10
xsize 200
label "Her name is..."
frame:
xalign 0.5
xfill True
padding (10,10)
input value ScreenVariableInputValue("name") pixel_width 200 length 30
$ name = name.strip()
if name in npcs:
text "The name is taken, please choose something else.":
color "#f00"
else:
textbutton _("Done!"):
action [SetVariable("persistent.mcname",If(name,name,"Mary Sue")),Return()]
## if name is left empty, we default back to Mary Sue
Code: Select all
## in screens.rpy, in screen preferences(), where it says something like "additional vboxes can be added for user-defined preferences"
hbox:
spacing 10
image "mc icon.png": ## again optional to show the MC design
size (100,100)
vbox:
label _("Main character")
default name_changing = False ## by default, the input is hidden, we display the name and a link to change it
if not name_changing:
text "Current name: [persistent.mcname]"
textbutton _("Change name") action SetScreenVariable("name_changing",True)
else:
default name = persistent.mcname or "Mary Sue" ## this setting is available before starting a game, so we add a default again
frame:
xsize 220
padding (10,10)
input value ScreenVariableInputValue("name") pixel_width 200 length 30
$ name = name.strip()
if name in npcs:
text "The name is taken, please choose something else.":
color "#f00"
else:
textbutton _("Done!"):
action [SetVariable("persistent.mcname",If(name,name,"Mary Sue")),SetScreenVariable("name_changing",False)]
## again, if left empty, we default to Mary Sue. we also hide the input again.
Let me know if you have suggestions, comments, questions, etc.