Screen to change player names

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
DrGonzo
Regular
Posts: 46
Joined: Fri Feb 23, 2018 9:12 pm
Location: Los Angeles, California
Contact:

Screen to change player names

#1 Post by DrGonzo »

Hi!
I'm trying to make a screen that lets a player change the names of some of the characters in my game.

There is a button on that screen that allows text input to change the name variable.

Code: Select all

screen names():
    tag menu
    use game_menu(_("Character Names"), scroll="viewport"):

        window: 
            add "player_names.png"

            button:
                text "Change character names"
                xalign 0.5
                ypos 700
                action Show ("input_screen")
My problem is that I can't get back to the character screen after text input to allow the player to change other names as well
I basically like to loop this until the player presses Return to get back to the game.

I've been pulling my hair out trying to get this to work, so any help is appreciated.

I'd like to return to this screen after text input.
lemma1.png
Google search: "renpy thisismyquestion -org"
This gives you everything - except renpy.org results. Which I find useless 90% of the time.

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Screen to change player names

#2 Post by enaielei »

Why don't you just put the text input inside the character names screen instead?

Code: Select all

default char1 = "Jessica"
default char2 = "Mike"

define mc = Character("char1", dynamic=True)
define other = Character("char2", dynamic=True)

screen char_names():
  default names = (("char1", "imagename"), ("char2", "imagename"))
  default count = len(names)

  default cols = 5
  default rows = ((count - (count % (cols + 1))) / (cols + 1)) + 1

  default input_values = tuple(VariableInputValue(c, returnable=False) for c, i in names)
  default selected = -1

  # the character button (picture of each character...)
  vbox:
    grid cols rows:
      for i in range(cols * rows):
        if i not in range(count):
          null
        else:
          $ char_name, img_name = names[i]
          button:
            action SetScreenVariable("selected", i)
            xysize (200, 200)
            vbox:
              add img_name
              text char_name

    if selected >= 0:
      input:
        value input_values[selected]
If you still prefer the input as a separate screen, then the approach is very similar...

Code: Select all

default char1 = "Jessica"
default char2 = "Mike"

define mc = Character("[char1]", dynamic=True)
define other = Character("[char2]", dynamic=True)

screen edit_name(name):
  default input_value = VariableInputValue(name, returnable=False)
  
  key "K_RETURN" action Hide("edit_name")
  vbox:
    input value input_value
    textbutton "Back" action Hide("edit_name")

screen char_names():
  # e.g. button for mike
  textbutton "Mike" action Show("edit_name", None, "char2")
Last edited by enaielei on Mon Dec 06, 2021 7:40 pm, edited 2 times in total.

User avatar
DrGonzo
Regular
Posts: 46
Joined: Fri Feb 23, 2018 9:12 pm
Location: Los Angeles, California
Contact:

Re: Screen to change player names

#3 Post by DrGonzo »

I'll give that a shot, thanks!
Google search: "renpy thisismyquestion -org"
This gives you everything - except renpy.org results. Which I find useless 90% of the time.

User avatar
DrGonzo
Regular
Posts: 46
Joined: Fri Feb 23, 2018 9:12 pm
Location: Los Angeles, California
Contact:

Re: Screen to change player names

#4 Post by DrGonzo »

Hi enaielei,
I'm getting somewhere with your code example.
Could I trouble you to help me one more time, please?

I'm not sure how to proceed after the input.
The cursor basically just sits there after typing in a new name.
Not sure how to use the new input value to actually change the selected characters name.

Code: Select all

screen char_names:

    default names = (("char1", "imagename"), ("char2", "imagename"))
    default count = len(names)

    default cols = 5
    default rows = ((count - (count % (cols + 1))) / (cols + 1)) + 1

    default input_values = tuple(VariableInputValue(c, returnable=False) for c, i in names)
    default selected = -1

    tag menu

    ## This use statement includes the game_menu screen inside this one. The
    ## vbox child is then included inside the viewport inside the game_menu
    ## screen.
    use game_menu(_("Rename Characters"), scroll="viewport"):

        style_prefix "about"

        window:
            add "gui/player_names.png"

            # the character button (picture of each character...)
            vbox:

                text "{color=#fff}{size=-10}[name_angela]{/size}{/color}"
                xpos 0
                ypos 238

                grid cols rows:
                  for i in range(cols * rows):
                    if i not in range(count):
                      null
                    else:
                      $ char_name, img_name = names[i]
                      button:
                        action SetScreenVariable("selected", i)
                        xysize (200, 200)
                        vbox:
                          add img_name
                          text char_name

                if selected >= 0:
                    input:
                        value input_values[selected]     <-------------------------   What to do after this?
Thanks for your help! :)

Screen.png
Google search: "renpy thisismyquestion -org"
This gives you everything - except renpy.org results. Which I find useless 90% of the time.

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Screen to change player names

#5 Post by enaielei »

The code should work alright. What you need to do is to just replace the `names` variable for your characters.
In my example, there are char1, char2 string variables defined these are then used in your Character objects (define mc) etc...
Then you just need to use the right name for the variables.

Code: Select all

default jessica_name = "Jessica"
default mike_name = "Mike"

define jessica = Character("jessica_name", dynamic=True) # dynamic=True is important here, otherwise you'll just see literally "[jessica_name]"
define mike = Character("mike_name", dynamic=True)

screen char_names():
  default names = (("jessica_name", "your image for the jessica character"), ("mike_name", "your image for mike"))
  ...
If you want to make the input toggle-able (your issue regarding the cursor just sitting there). You can replace these lines...

Code: Select all

$ char_name, img_name = names[i]
button:
  action SetScreenVariable("selected", i)
with

Code: Select all

$ char_name, img_name = names[i]
button:
  action ToggleScreenVariable("selected", i, -1)
This makes your imagebuttons for each character toggle-able, so first click it's selected second it's not. you get the idea.
Not sure how to use the new input value to actually change the selected characters name.
The VariableInputValue(...) does that. Everytime you hit a key it gets assigned directly to the variable name you specified.
Last edited by enaielei on Mon Dec 06, 2021 7:40 pm, edited 1 time in total.

User avatar
DrGonzo
Regular
Posts: 46
Joined: Fri Feb 23, 2018 9:12 pm
Location: Los Angeles, California
Contact:

Re: Screen to change player names

#6 Post by DrGonzo »

OK, great!
I'll implement this.

Thank you so much!
Google search: "renpy thisismyquestion -org"
This gives you everything - except renpy.org results. Which I find useless 90% of the time.

User avatar
DrGonzo
Regular
Posts: 46
Joined: Fri Feb 23, 2018 9:12 pm
Location: Los Angeles, California
Contact:

Re: Screen to change player names

#7 Post by DrGonzo »

Hi enaielei,
Here's the problem I keep running into:

With this code

Code: Select all

default name_angela = "Angela"
default name_bibi = "Bibi"

define a = Character("[name_angela]", dynamic=True, image="angela", who_color="FF7FFF", who_outlines=[ (2, "#333333", 0, 0) ], what_outlines=[ (2, "#333333", 0, 0)])
define b = Character("[name_bibi]", dynamic=True, image="bibi", who_color="FF7F7F", who_outlines=[ (2, "#333333", 0, 0) ], what_outlines=[ (2, "#333333", 0, 0) ])

screen char_names():    
    tag menu
    default names = (("name_angela", "your image for the jessica character"), ("name_bibi", "your image for mike"))    <----- name_angela in parenthesis
I get this:

lemma2.png


When I change
default names = (("name_angela", "your image for the jessica character")
to
default names = (([name_angela], "your image for the jessica character") with square brackets instead of parenthesis, it get the actual content of the variable, the characters name. But then I get an error when selecting that character to change the name.


Character name shows correctly, not the variable name.

lemma3.png


Error with brackets instead of parenthesis

Code: Select all

  File "game/screens.rpy", line 1560, in execute
    vbox:
  File "game/screens.rpy", line 1575, in execute
    if selected >= 0:
  File "game/screens.rpy", line 1576, in execute
    input:
  File "D:\RenPy Local\renpy-7.3.5-sdk\renpy\display\behavior.py", line 1154, in __init__
    default = value.get_text()
  File "renpy/common/00inputvalues.rpy", line 145, in get_text
    return globals()[self.variable]
TypeError: unhashable type: 'RevertableList'
I can't believe that this is so difficult in RenPy.
I'm actually a seasoned programmer, just not in RenPy.

Do you have any idea where this is going south?
Thanks for your help!
Google search: "renpy thisismyquestion -org"
This gives you everything - except renpy.org results. Which I find useless 90% of the time.

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Screen to change player names

#8 Post by enaielei »

My bad, you supposed to omit the [].
so try...

Code: Select all

Character("name_angela", dynamic=True)
*Updated the previous codes based on this*

Additional edit:
If you want to actually update this part when the name is changed...

Code: Select all

vbox:
  add img_name
  text char_name
change it to...

Code: Select all

vbox:
  add img_name
  text getattr(store, char_name)
Or better yet, you can eliminate the input below the code and place it in the vbox itself so it will look like the label name is editable.

Code: Select all

vbox:
  add img_name
  if selected >= 0 and selected == i:
    input:
      value input_values[selected]
  else:
      text getattr(store, char_name)

Post Reply

Who is online

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