Chooseable color of name [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.
Post Reply
Message
Author
Exanimem
Newbie
Posts: 9
Joined: Tue Jun 30, 2015 7:17 pm
Contact:

Chooseable color of name [SOLVED]

#1 Post by Exanimem » Tue Jun 30, 2015 7:23 pm

I tried to make a choosable hex code like so

Code: Select all

define P = DynamicCharacter('player_name', color="hex_code") 

Code: Select all

menu:
    
    "Blue":
        $ hex_code = "#0000ff"
        
    "Brown":
        $ hex_code = "#a52a2a"

    "Green":
        $ hex_code = "#008000"

    "Grey":
        $ hex_code = "#808080"
    
    "Orange":
        $ hex_code = "#ffa500"
    
    "Pink":
        $ hex_code = "#fc0cb"
    
    "Purple":
        $ hex_code = "#800080"
    
    "Red":
        $ hex_code = "#ff0000"
    
    "White":
        $ hex_code = "#ffffff"
   
    "Yellow":
        $ hex_code = "#fff00"
        
    "Select what color you'd like your name to be in"
When I then run this, whenever I get to a section where it displays the inputed name I get this error:

I'm sorry, but an uncaught exception occurred.

While processing the color property of anonymous style:
File "game/script.rpy", line 100, in script
P "Watch me"
ValueError: invalid literal for int() with base 16: 'he'

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

Full traceback:
File "game/script.rpy", line 100, in script
P "Watch me"
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\ast.py", line 593, in execute
renpy.exports.say(who, what, interact=self.interact)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\exports.py", line 1021, in say
who(what, interact=interact)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\character.py", line 826, in __call__
self.do_display(who, what, cb_args=self.cb_args, **display_args)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\character.py", line 688, in do_display
**display_args)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\character.py", line 491, in display_say
rv = renpy.ui.interact(mouse='say', type=type, roll_forward=roll_forward)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\ui.py", line 277, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\display\core.py", line 2276, in interact
repeat, rv = self.interact_core(preloads=preloads, **kwargs)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\display\core.py", line 2608, in interact_core
self.draw_screen(root_widget, fullscreen_video, (not fullscreen_video) or video_frame_drawn)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\display\core.py", line 1717, in draw_screen
renpy.config.screen_height,
File "renpy/display/render.pyx", line 379, in renpy.display.render.render_screen (gen\renpy.display.render.c:5886)
rv = render(root, width, height, 0, 0)
File "renpy/display/render.pyx", line 185, in renpy.display.render.render (gen\renpy.display.render.c:2662)
rv = d.render(widtho, heighto, st, at)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\display\layout.py", line 649, in render
surf = render(child, width, height, cst, cat)
File "renpy/display/render.pyx", line 103, in renpy.display.render.render (gen\renpy.display.render.c:3045)
cpdef render(d, object widtho, object heighto, double st, double at):
File "renpy/display/render.pyx", line 185, in renpy.display.render.render (gen\renpy.display.render.c:2662)
rv = d.render(widtho, heighto, st, at)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\display\layout.py", line 649, in render
surf = render(child, width, height, cst, cat)
File "renpy/display/render.pyx", line 103, in renpy.display.render.render (gen\renpy.display.render.c:3045)
cpdef render(d, object widtho, object heighto, double st, double at):
File "renpy/display/render.pyx", line 185, in renpy.display.render.render (gen\renpy.display.render.c:2662)
rv = d.render(widtho, heighto, st, at)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\display\layout.py", line 649, in render
surf = render(child, width, height, cst, cat)
File "renpy/display/render.pyx", line 103, in renpy.display.render.render (gen\renpy.display.render.c:3045)
cpdef render(d, object widtho, object heighto, double st, double at):
File "renpy/display/render.pyx", line 185, in renpy.display.render.render (gen\renpy.display.render.c:2662)
rv = d.render(widtho, heighto, st, at)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\display\screen.py", line 597, in render
child = renpy.display.render.render(self.child, w, h, st, at)
File "renpy/display/render.pyx", line 103, in renpy.display.render.render (gen\renpy.display.render.c:3045)
cpdef render(d, object widtho, object heighto, double st, double at):
File "renpy/display/render.pyx", line 185, in renpy.display.render.render (gen\renpy.display.render.c:2662)
rv = d.render(widtho, heighto, st, at)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\display\layout.py", line 649, in render
surf = render(child, width, height, cst, cat)
File "renpy/display/render.pyx", line 103, in renpy.display.render.render (gen\renpy.display.render.c:3045)
cpdef render(d, object widtho, object heighto, double st, double at):
File "renpy/display/render.pyx", line 185, in renpy.display.render.render (gen\renpy.display.render.c:2662)
rv = d.render(widtho, heighto, st, at)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\display\layout.py", line 995, in render
st, at)
File "renpy/display/render.pyx", line 103, in renpy.display.render.render (gen\renpy.display.render.c:3045)
cpdef render(d, object widtho, object heighto, double st, double at):
File "renpy/display/render.pyx", line 185, in renpy.display.render.render (gen\renpy.display.render.c:2662)
rv = d.render(widtho, heighto, st, at)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\display\layout.py", line 808, in render
surf = render(d, width - x, rh, cst, cat)
File "renpy/display/render.pyx", line 103, in renpy.display.render.render (gen\renpy.display.render.c:3045)
cpdef render(d, object widtho, object heighto, double st, double at):
File "renpy/display/render.pyx", line 147, in renpy.display.render.render (gen\renpy.display.render.c:2215)
xmaximum = style.xmaximum
File "module/gen/styleclass.pxi", line 389, in renpy.styledata.styleclass.Style.xmaximum.__get__ (gen\renpy.styledata.styleclass.c:10674)
File "renpy/style.pyx", line 473, in renpy.style.StyleCore._get (gen\renpy.style.c:7023)
build_style(self)
File "renpy/style.pyx", line 671, in renpy.style.build_style (gen\renpy.style.c:9844)
raise
File "renpy/style.pyx", line 668, in renpy.style.build_style (gen\renpy.style.c:9734)
pfw.function(s.cache, cache_priorities, priority, v)
File "style_functions.pyx", line 705, in style_functions.color_property (gen\renpy.styledata.style_functions.c:7126)
File "C:\Users\Burke\Desktop\Brian\Programming\Visual Novel\renpy-6.99.4-sdk\renpy\easy.py", line 50, in color
r = int(c[0]+c[1], 16)
ValueError: invalid literal for int() with base 16: 'he'

Windows-7-6.1.7601-SP1
Ren'Py 6.99.4.467
TestGame 0.0

How do I fix this?
Last edited by Exanimem on Wed Jul 01, 2015 12:53 pm, edited 1 time in total.

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Chhoseable color of name

#2 Post by SinnyROM » Tue Jun 30, 2015 7:36 pm

Removing the quotations around the variable hex_code should work. Make sure you define it before you define the character too.

Exanimem
Newbie
Posts: 9
Joined: Tue Jun 30, 2015 7:17 pm
Contact:

Re: Chhoseable color of name

#3 Post by Exanimem » Tue Jun 30, 2015 7:41 pm

What would I define it as? Color doesn't work. And my apologizes if it's a stupid question, I've only started Ren'Py yesterday.

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Chhoseable color of name

#4 Post by SinnyROM » Tue Jun 30, 2015 9:14 pm

No worries, we all start somewhere. You can define it how you did in the choices, or using the define keyword. Also, use Character instead - I think DynamicCharacter is deprecated.

Code: Select all

define player_name = "Placeholder"
define hex_code = "#ffffff" #default is white
define P = Character(player_name, color=hex_code)

Exanimem
Newbie
Posts: 9
Joined: Tue Jun 30, 2015 7:17 pm
Contact:

Re: Chhoseable color of name

#5 Post by Exanimem » Tue Jun 30, 2015 9:42 pm

When I use your code, my name is always "Placeholder" and hex white no matter what.

Exanimem
Newbie
Posts: 9
Joined: Tue Jun 30, 2015 7:17 pm
Contact:

Re: Chhoseable color of name

#6 Post by Exanimem » Tue Jun 30, 2015 9:45 pm

Also, here is the code for name input.

Code: Select all

   $ player_name = renpy.input("What is your name?")

    $ player_name = player_name.strip()
    
    if player_name == "":
        $ player_name="Brian"
   

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Chhoseable color of name

#7 Post by SinnyROM » Wed Jul 01, 2015 9:19 am

That should've worked fine - I even have that in another game I'm working on, but I tried it now and it's not working! I think something changed in-between Ren'Py updates.
The documentation mentions the argument dynamic=True for characters with variable names, so this works:

Code: Select all

define P = Character("player_name", dynamic=True)
The hex_code variable however doesn't change the character's name colour, or text colour. The variable itself changes value after selecting, but not the character's color value. I got a workaround to work by directly editing the character's who arguments. Also, place the prompt text right after the menu keyword so it shows along with the choices.

Code: Select all

menu:
    # Prompt for choice menu
    "Select what color you'd like your name to be in"

    "Blue":
        $ hex_code = "#0000ff"
        
    "Brown":
        $ hex_code = "#a52a2a"

    "Green":
        $ hex_code = "#008000"

    "Grey":
        $ hex_code = "#808080"
    
    "Orange":
        $ hex_code = "#ffa500"
    
    "Pink":
        $ hex_code = "#fc0cb"
    
    "Purple":
        $ hex_code = "#800080"
    
    "Red":
        $ hex_code = "#ff0000"
    
    "White":
        $ hex_code = "#ffffff"
   
    "Yellow":
        $ hex_code = "#fff00"

label after_choice:
        
    # Change the character's value directly
    $ P.who_args['color'] = hex_code

    P "Test"
I don't know if this is the best way of updating a character, but it works. If anyone does have a better idea though, feel free to mention it.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Chhoseable color of name

#8 Post by nyaatrap » Wed Jul 01, 2015 10:20 am

It seems say characters can be defined after start even they aren't defined in an init block. The following works:

Code: Select all

label start:
   $name=renpy.input()
   menu:
      "colorA":
          $P=Character(name, color="#fff")

   p "hello"

Exanimem
Newbie
Posts: 9
Joined: Tue Jun 30, 2015 7:17 pm
Contact:

Re: Chhoseable color of name

#9 Post by Exanimem » Wed Jul 01, 2015 12:42 pm

Thank you both so much! I got it working!

Post Reply

Who is online

Users browsing this forum: Ocelot