Custom Namebox for Different Characters? [Solved]

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.
Message
Author
User avatar
Katy133
Miko-Class Veteran
Posts: 703
Joined: Sat Nov 16, 2013 1:21 pm
Completed: Eight Sweets, The Heart of Tales, [redacted] Life, Must Love Jaws, A Tune at the End of the World, Three Guys That Paint, The Journey of Ignorance, Portal 2.5.
Projects: The Butler Detective
Tumblr: katy-133
Deviantart: Katy133
Soundcloud: Katy133
itch: katy133
Location: Canada
Contact:

Custom Namebox for Different Characters? [Solved]

#1 Post by Katy133 » Fri Apr 12, 2019 3:54 pm

I'm trying to customise the namebox on the textbox so that it changes art assets (.png files) depending on who is speaking: A green namebox for character A, a blue namebox for character B, and a pink for everyone else.

Know how to edit the Say screen to use one namebox colour, but I don't know how to switch between different ones depending on the character.

Code: Select all

style namebox:
    xpos gui.name_xpos
    xanchor gui.name_xalign
    xsize gui.namebox_width
    ypos gui.name_ypos
    ysize gui.namebox_height

    background "gui/textbox/name tag green.png" #The green namebox image file
    padding gui.namebox_borders.padding
Last edited by Katy133 on Sat Apr 13, 2019 12:04 pm, edited 1 time in total.
ImageImage

My Website, which lists my visual novels.
Become a patron on my Patreon!

User avatar
Per K Grok
Miko-Class Veteran
Posts: 774
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1 & 2
Projects: the Phantom Flier
itch: per-k-grok
Location: Sverige
Contact:

Re: Custom Namebox for Different Characters?

#2 Post by Per K Grok » Fri Apr 12, 2019 5:00 pm

Katy133 wrote:
Fri Apr 12, 2019 3:54 pm
I'm trying to customise the namebox on the textbox so that it changes art assets (.png files) depending on who is speaking: A green namebox for character A, a blue namebox for character B, and a pink for everyone else.

Know how to edit the Say screen to use one namebox colour, but I don't know how to switch between different ones depending on the character.

Code: Select all

style namebox:
    xpos gui.name_xpos
    xanchor gui.name_xalign
    xsize gui.namebox_width
    ypos gui.name_ypos
    ysize gui.namebox_height

    background "gui/textbox/name tag green.png" #The green namebox image file
    padding gui.namebox_borders.padding
You could just use window_background when define the character.

define De = Character("Delivery man", what_color="#ff6", window_background="gui/textbox3.png", image="DM")

User avatar
Katy133
Miko-Class Veteran
Posts: 703
Joined: Sat Nov 16, 2013 1:21 pm
Completed: Eight Sweets, The Heart of Tales, [redacted] Life, Must Love Jaws, A Tune at the End of the World, Three Guys That Paint, The Journey of Ignorance, Portal 2.5.
Projects: The Butler Detective
Tumblr: katy-133
Deviantart: Katy133
Soundcloud: Katy133
itch: katy133
Location: Canada
Contact:

Re: Custom Namebox for Different Characters?

#3 Post by Katy133 » Fri Apr 12, 2019 5:29 pm

Per K Grok wrote:
Fri Apr 12, 2019 5:00 pm
You could just use window_background when define the character.

define De = Character("Delivery man", what_color="#ff6", window_background="gui/textbox3.png", image="DM")
I'm trying that out, but it ends up replacing the entire textbox image with the namebox image.
ImageImage

My Website, which lists my visual novels.
Become a patron on my Patreon!

User avatar
Matalla
Veteran
Posts: 202
Joined: Wed Mar 06, 2019 6:22 pm
Completed: The Lost Smile
itch: matalla-interactive
Location: Spain
Contact:

Re: Custom Namebox for Different Characters?

#4 Post by Matalla » Fri Apr 12, 2019 7:16 pm

Not textbox, namebox. They should be different files and different style definitions. Textbox is for the dialogue, namebox is... well, for names.
Comunidad Ren'Py en español (Discord)
Honest Critique

User avatar
Katy133
Miko-Class Veteran
Posts: 703
Joined: Sat Nov 16, 2013 1:21 pm
Completed: Eight Sweets, The Heart of Tales, [redacted] Life, Must Love Jaws, A Tune at the End of the World, Three Guys That Paint, The Journey of Ignorance, Portal 2.5.
Projects: The Butler Detective
Tumblr: katy-133
Deviantart: Katy133
Soundcloud: Katy133
itch: katy133
Location: Canada
Contact:

Re: Custom Namebox for Different Characters?

#5 Post by Katy133 » Fri Apr 12, 2019 7:57 pm

Matalla wrote:
Fri Apr 12, 2019 7:16 pm
Not textbox, namebox. They should be different files and different style definitions. Textbox is for the dialogue, namebox is... well, for names.
I am using a namebox art asset. I basically took Per K Grok's code and edited/placed it as:

Code: Select all

define boy = Character("Boy", window_background="gui/textbox/name tag blue.png", image="boy", ctc="ctc", ctc_position="fixed")
Or did you mean something else was incorrect about the code? Should the "window_background" part be different?
ImageImage

My Website, which lists my visual novels.
Become a patron on my Patreon!

User avatar
Matalla
Veteran
Posts: 202
Joined: Wed Mar 06, 2019 6:22 pm
Completed: The Lost Smile
itch: matalla-interactive
Location: Spain
Contact:

Re: Custom Namebox for Different Characters?

#6 Post by Matalla » Fri Apr 12, 2019 8:18 pm

It should be:

Code: Select all

define boy = Character("Boy", namebox_background="gui/textbox/name tag blue.png", image="boy", ctc="ctc", ctc_position="fixed")
window_background is the textbox for the dialogue. In general, you should look up in the gui and the styles definitions first to see what element you're trying to change.

Code: Select all

style window:
    xalign 0.5
    xfill True
    yalign gui.textbox_yalign
    ysize gui.textbox_height

    background Image("gui/textbox.png", xalign=0.5, yalign=1.0)

style namebox:
    xpos gui.name_xpos
    xanchor gui.name_xalign
    xsize gui.namebox_width
    ypos gui.name_ypos
    ysize gui.namebox_height
    background Frame("gui/namebox.png", gui.namebox_borders, tile=gui.namebox_tile, xalign=gui.name_xalign)
    padding gui.namebox_borders.padding
Here you can see that the element you're trying to change is namebox, not window (if it's an image, you go can to the specified folder and open the image to see what is it). So if the style is named "namebox" and you're trying to change the background it's namebox_background.
Comunidad Ren'Py en español (Discord)
Honest Critique

User avatar
Katy133
Miko-Class Veteran
Posts: 703
Joined: Sat Nov 16, 2013 1:21 pm
Completed: Eight Sweets, The Heart of Tales, [redacted] Life, Must Love Jaws, A Tune at the End of the World, Three Guys That Paint, The Journey of Ignorance, Portal 2.5.
Projects: The Butler Detective
Tumblr: katy-133
Deviantart: Katy133
Soundcloud: Katy133
itch: katy133
Location: Canada
Contact:

Re: Custom Namebox for Different Characters?

#7 Post by Katy133 » Fri Apr 12, 2019 8:35 pm

Matalla wrote:
Fri Apr 12, 2019 8:18 pm
It should be:

Code: Select all

define boy = Character("Boy", namebox_background="gui/textbox/name tag blue.png", image="boy", ctc="ctc", ctc_position="fixed")
I've tried that, but it isn't changing the namebox's color. It's staying the same colour that I've set it as under the "style namebox:" section of code.
ImageImage

My Website, which lists my visual novels.
Become a patron on my Patreon!

User avatar
Matalla
Veteran
Posts: 202
Joined: Wed Mar 06, 2019 6:22 pm
Completed: The Lost Smile
itch: matalla-interactive
Location: Spain
Contact:

Re: Custom Namebox for Different Characters?

#8 Post by Matalla » Fri Apr 12, 2019 8:51 pm

It should show the image "name tag blue.png" in the "gui/textbox/" folder. I just checked in one of my projects and it works. I don't know what you're talking about with "the same colour that I've set it as under the "style namebox:" section of code". Image files don't change colors with a line of code. It either display the image or not. If you're talking about a box generated with a certain style (a solid color, borders, etc.), then we're not talking about image files and .png and folders have no meaning in that context. You'll have to have different image files, each one as you want it to look and then you can assign each image to a character.
Comunidad Ren'Py en español (Discord)
Honest Critique

User avatar
Katy133
Miko-Class Veteran
Posts: 703
Joined: Sat Nov 16, 2013 1:21 pm
Completed: Eight Sweets, The Heart of Tales, [redacted] Life, Must Love Jaws, A Tune at the End of the World, Three Guys That Paint, The Journey of Ignorance, Portal 2.5.
Projects: The Butler Detective
Tumblr: katy-133
Deviantart: Katy133
Soundcloud: Katy133
itch: katy133
Location: Canada
Contact:

Re: Custom Namebox for Different Characters?

#9 Post by Katy133 » Fri Apr 12, 2019 9:48 pm

Matalla wrote:
Fri Apr 12, 2019 8:51 pm
It should show the image "name tag blue.png" in the "gui/textbox/" folder. I just checked in one of my projects and it works. I don't know what you're talking about with "the same colour that I've set it as under the "style namebox:" section of code". Image files don't change colors with a line of code. It either display the image or not. If you're talking about a box generated with a certain style (a solid color, borders, etc.), then we're not talking about image files and .png and folders have no meaning in that context. You'll have to have different image files, each one as you want it to look and then you can assign each image to a character.
What I meant was, in my "gui/textbox/" folder, I have three nameboxes of different colors: name tag green.png, name tag blue.png, and name tag pink.png

I've defined:

Code: Select all

define boy = Character("Boy", image="boy", namebox_background="gui/textbox/name tag blue.png", ctc="ctc", ctc_position="fixed")#A blue namebox
And I have under the "style namebox" section:

Code: Select all

style namebox:
    xpos gui.name_xpos
    xanchor gui.name_xalign
    xsize gui.namebox_width
    ypos gui.name_ypos
    ysize gui.namebox_height

    background Frame("gui/textbox/name tag pink.png", gui.namebox_borders, tile=gui.namebox_tile, xalign=gui.name_xalign)#The pink namebox
    padding gui.namebox_borders.padding
But when the character speaks, it's still showing the pink namebox, not the blue one.
ImageImage

My Website, which lists my visual novels.
Become a patron on my Patreon!

User avatar
Per K Grok
Miko-Class Veteran
Posts: 774
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1 & 2
Projects: the Phantom Flier
itch: per-k-grok
Location: Sverige
Contact:

Re: Custom Namebox for Different Characters?

#10 Post by Per K Grok » Sat Apr 13, 2019 2:22 am

Katy133 wrote:
Fri Apr 12, 2019 9:48 pm
Matalla wrote:
Fri Apr 12, 2019 8:51 pm
It should show the image "name tag blue.png" in the "gui/textbox/" folder. I just checked in one of my projects and it works. I don't know what you're talking about with "the same colour that I've set it as under the "style namebox:" section of code". Image files don't change colors with a line of code. It either display the image or not. If you're talking about a box generated with a certain style (a solid color, borders, etc.), then we're not talking about image files and .png and folders have no meaning in that context. You'll have to have different image files, each one as you want it to look and then you can assign each image to a character.
What I meant was, in my "gui/textbox/" folder, I have three nameboxes of different colors: name tag green.png, name tag blue.png, and name tag pink.png

I've defined:

Code: Select all

define boy = Character("Boy", image="boy", namebox_background="gui/textbox/name tag blue.png", ctc="ctc", ctc_position="fixed")#A blue namebox
And I have under the "style namebox" section:

Code: Select all

style namebox:
    xpos gui.name_xpos
    xanchor gui.name_xalign
    xsize gui.namebox_width
    ypos gui.name_ypos
    ysize gui.namebox_height

    background Frame("gui/textbox/name tag pink.png", gui.namebox_borders, tile=gui.namebox_tile, xalign=gui.name_xalign)#The pink namebox
    padding gui.namebox_borders.padding
But when the character speaks, it's still showing the pink namebox, not the blue one.
Sorry for causing the initial confusion. I started out with the assumption that it was the textbox you wanted to change and then misread what you wrote from that assumption.

With namebox I would go a slightly different way. I would make a different style for namebox in the screen.rpy and call the style of namebox when defining the character.

Code: Select all


style namebox:
    xpos gui.name_xpos
    xanchor gui.name_xalign
    xsize gui.namebox_width
    ypos gui.name_ypos
    ysize gui.namebox_height

    background Frame("gui/textbox/name tag pink.png", gui.namebox_borders, tile=gui.namebox_tile, xalign=gui.name_xalign)#The pink namebox
    padding gui.namebox_borders.padding

style nameboxRed:
    xpos gui.name_xpos
    xanchor gui.name_xalign
    xsize gui.namebox_width
    ypos gui.name_ypos
    ysize gui.namebox_height

    background Frame("gui/textbox/name tag red.png", gui.namebox_borders, tile=gui.namebox_tile, xalign=gui.name_xalign)#The red namebox
    padding gui.namebox_borders.padding

Code: Select all

define boy = Character("Boy", image="boy", namebox_style="nameboxRed", ctc="ctc", ctc_position="fixed")
namebox_background should work too, but I think it would not adjust the image to the box size.

User avatar
Matalla
Veteran
Posts: 202
Joined: Wed Mar 06, 2019 6:22 pm
Completed: The Lost Smile
itch: matalla-interactive
Location: Spain
Contact:

Re: Custom Namebox for Different Characters?

#11 Post by Matalla » Sat Apr 13, 2019 9:54 am

Katy133 wrote:
Fri Apr 12, 2019 9:48 pm
...
It's either a bug or a piece of code somewhere else that contradicts that. I tested and it works. Why don't you test it in a blank project where it should be easier to troubleshoot it? Start only with the style definitions, the nameboxes files and some lines of dialogue.
Per K Grok wrote:
Sat Apr 13, 2019 2:22 am
...
Both methods should work because they do the same. If the only difference between the 2 namebox styles is the namebox file, it's the same thing. The namebox you use in the character inherits all properties not specified for the default namebox, including the size, so it won't be a problem.
Comunidad Ren'Py en español (Discord)
Honest Critique

User avatar
Katy133
Miko-Class Veteran
Posts: 703
Joined: Sat Nov 16, 2013 1:21 pm
Completed: Eight Sweets, The Heart of Tales, [redacted] Life, Must Love Jaws, A Tune at the End of the World, Three Guys That Paint, The Journey of Ignorance, Portal 2.5.
Projects: The Butler Detective
Tumblr: katy-133
Deviantart: Katy133
Soundcloud: Katy133
itch: katy133
Location: Canada
Contact:

Re: Custom Namebox for Different Characters?

#12 Post by Katy133 » Sat Apr 13, 2019 12:04 pm

Matalla wrote:
Sat Apr 13, 2019 9:54 am
It's either a bug or a piece of code somewhere else that contradicts that. I tested and it works. Why don't you test it in a blank project where it should be easier to troubleshoot it? Start only with the style definitions, the nameboxes files and some lines of dialogue.
I made a blank project and compared the two screen.rpy files to see what was different, and I discovered what was causing the issue:

Code: Select all

screen say(who, what):
    style_prefix "say"

    window:
        id "window"

        text what id "what"

        if who is not None:

            window:
                id "namebox"##This was what I was missing. This lets me change the namebox to different colours for different characters
                style "namebox"
                text who id "who"

    if not renpy.variant("small"):
        add SideImage() xalign 0.0 yalign 1.0
And I was missing this line right underneath:

Code: Select all

## Make the namebox available for styling through the Character object.
init python:
    config.character_id_prefixes.append('namebox')
Then I added the different namebox styles:

Code: Select all

style namebox:
    xpos gui.name_xpos
    xanchor gui.name_xalign
    xsize gui.namebox_width
    ypos gui.name_ypos
    ysize gui.namebox_height

    background Frame("gui/textbox/name tag pink.png", gui.namebox_borders, tile=gui.namebox_tile, xalign=gui.name_xalign)
    padding gui.namebox_borders.padding
    
style nameboxgreen:
    xpos gui.name_xpos
    xanchor gui.name_xalign
    xsize gui.namebox_width
    ypos gui.name_ypos
    ysize gui.namebox_height

    background Frame("gui/textbox/name tag green.png", gui.namebox_borders, tile=gui.namebox_tile, xalign=gui.name_xalign)
    padding gui.namebox_borders.padding
Then I defined the characters, as Per K Grok wrote it:

Code: Select all

define b = Character("Boy", image="boy", namebox_style="nameboxgreen", ctc="ctc", ctc_position="fixed")
(I discovered that it needs to be defined as namebox_style="nameboxgreen" . If you use namebox_background="gui/textbox/name tag green.png" , it uses the green namebox, but it removes any custom borders you've programmed.)
It works now! Thank you SO much, Matalla and Per K Grok! :D
ImageImage

My Website, which lists my visual novels.
Become a patron on my Patreon!

Tendo64
Newbie
Posts: 8
Joined: Sat Jun 08, 2019 6:52 pm
Contact:

Re: Custom Namebox for Different Characters? [Solved]

#13 Post by Tendo64 » Tue Jun 11, 2019 3:18 pm

Hey, so I found this thread and did all that was said here (in my case, I am making separate name boxes for male and female characters, as you might see in the traceback), but it's giving me this error:
I'm sorry, but an uncaught exception occurred.

After initialization, but before game start.
File "renpy/common/00start.rpy", line 79, in _init_language
renpy.change_language(language)
File "game/screens.rpy", line 127, in <module>
background Frame("gui/namebox_f.png", gui.namebox_borders, tile=gui.namebox_title, xalign=gui.name_xalign)
AttributeError: 'StoreModule' object has no attribute 'namebox_title'

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

Full traceback:
File "C:\Users\<Username>\Downloads\Ren'PY\renpy-7.2.2-sdk\renpy\bootstrap.py", line 313, in bootstrap
renpy.main.main()
File "C:\Users\<Username>\Downloads\Ren'PY\renpy-7.2.2-sdk\renpy\main.py", line 525, in main
run(restart)
File "C:\Users\<Username>\Downloads\Ren'PY\renpy-7.2.2-sdk\renpy\main.py", line 71, in run
renpy.translation.init_translation()
File "C:\Users\<Username>\Downloads\Ren'PY\renpy-7.2.2-sdk\renpy\translation\__init__.py", line 558, in init_translation
renpy.store._init_language() # @UndefinedVariable
File "renpy/common/00start.rpy", line 79, in _init_language
renpy.change_language(language)
File "C:\Users\<Username>\Downloads\Ren'PY\renpy-7.2.2-sdk\renpy\translation\__init__.py", line 636, in change_language
new_change_language(tl, language)
File "C:\Users\<Username>\Downloads\Ren'PY\renpy-7.2.2-sdk\renpy\translation\__init__.py", line 604, in new_change_language
i.apply()
File "C:\Users\<Username.\Downloads\Ren'PY\renpy-7.2.2-sdk\renpy\ast.py", line 2474, in apply
value = renpy.python.py_eval(expr)
File "C:\Users\<Username>\Downloads\Ren'PY\renpy-7.2.2-sdk\renpy\python.py", line 1961, in py_eval
return py_eval_bytecode(code, globals, locals)
File "C:\Users\<Username>\Downloads\Ren'PY\renpy-7.2.2-sdk\renpy\python.py", line 1954, in py_eval_bytecode
return eval(bytecode, globals, locals)
File "game/screens.rpy", line 127, in <module>
background Frame("gui/namebox_f.png", gui.namebox_borders, tile=gui.namebox_title, xalign=gui.name_xalign)
AttributeError: 'StoreModule' object has no attribute 'namebox_title'
I can't for the life of me figure out what's wrong. Does anybody know?

User avatar
Autumnotopia
Regular
Posts: 48
Joined: Sun May 19, 2019 8:53 pm
Tumblr: autumnotopiadev
Github: autumngreenley
itch: autumnotopia
Contact:

Re: Custom Namebox for Different Characters? [Solved]

#14 Post by Autumnotopia » Tue Jun 11, 2019 4:06 pm

I'm not super sure, but it looks like it should be 'tile=gui.namebox_tile' instead of 'gui.namebox_title' on the line that it's complaining about

Tendo64
Newbie
Posts: 8
Joined: Sat Jun 08, 2019 6:52 pm
Contact:

Re: Custom Namebox for Different Characters? [Solved]

#15 Post by Tendo64 » Tue Jun 11, 2019 7:00 pm

Autumnotopia wrote:
Tue Jun 11, 2019 4:06 pm
I'm not super sure, but it looks like it should be 'tile=gui.namebox_tile' instead of 'gui.namebox_title' on the line that it's complaining about
Well, at least the project is launching, but now it's telling me this:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens.rpy", line 119: u'style' is not a keyword argument or valid child for the screen statement.
    style nameboxpink:
         ^

Ren'Py Version: Ren'Py 7.2.2.491
Tue Jun 11 18:53:23 2019
I basically did everything in that section, except I changed green to pink and changed the image file to what mine is. I don't get why it's telling me "style" isn't an argument when it's being used multiple times in the screen.rpy file already.

Post Reply

Who is online

Users browsing this forum: stcrs