[SOLVED]String variables passed into screen contain brackets and extra chatacters

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
GammaBreak
Regular
Posts: 62
Joined: Thu Aug 06, 2020 10:04 pm
Contact:

[SOLVED]String variables passed into screen contain brackets and extra chatacters

#1 Post by GammaBreak » Tue Oct 06, 2020 3:08 pm

I'm tinkering with screens and have run into an issue I can't find any sort of documentation on. My goal for a future project is to create a simple profile screen. User clicks a button and a screen comes up detailing some points about their character, and then the user can close the screen. Nothing fancy or complicated.

I've watched the tutorial on screens as well as the passing parameters into screens, but I'm stumped. I have the following code:

Code: Select all

menu:
        "What is your hair color?"
        "Black":
           $ hair_color = "Black"
        "Brown":
           $ hair_color = "Brown"
        "Blonde":
           $ hair_color = "Blonde"
        "Red":
           $ hair_color = "Red"
    label after_hair:
    
    menu:
        "Are you tall or short?"
        "Tall":
           $ height = "Tall"
        "Short":
           $ height = "Short"
        "Average":
           $ height = "Average"
    label after_height:

    screen profile_screen(hair_color, height, close=Return(True)):
        frame:
            xalign 0.5 ypos 50
            vbox:
                text _("Hair Color: [hair_color]. \nHeight: [height].")
                textbutton _("Close"):
                    action close
                    
    call screen profile_screen([hair_color], [height])
                
    "Finished"

User selects their height/hair color, then a screen gets called and displays it. What I get is the following:

Image

If I selected brown hair, the value of "Brown" gets loaded into $ hair_color, so why is it being displayed as [u'Brown']? I tried the same syntax from the tutorial and that yields the same issue. Am I not doing something with the variables correctly? I'm using some variables in my current project, so this would be good to learn and clear up, as maybe I'm missing something.
Last edited by GammaBreak on Tue Oct 06, 2020 4:29 pm, edited 1 time in total.

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
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-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: String variables passed into screen contain brackets and extra chatacters

#2 Post by Per K Grok » Tue Oct 06, 2020 4:05 pm

GammaBreak wrote:
Tue Oct 06, 2020 3:08 pm
I'm tinkering with screens and have run into an issue I can't find any sort of documentation on. My goal for a future project is to create a simple profile screen. User clicks a button and a screen comes up detailing some points about their character, and then the user can close the screen. Nothing fancy or complicated.

I've watched the tutorial on screens as well as the passing parameters into screens, but I'm stumped. I have the following code:

---

If I selected brown hair, the value of "Brown" gets loaded into $ hair_color, so why is it being displayed as [u'Brown']? I tried the same syntax from the tutorial and that yields the same issue. Am I not doing something with the variables correctly? I'm using some variables in my current project, so this would be good to learn and clear up, as maybe I'm missing something.
What works in ordinary renpy code does not always work in screens.

Try constructing your strings this way instead.

text _("Hair Color: " + hair_color)

That aught to work.

GammaBreak
Regular
Posts: 62
Joined: Thu Aug 06, 2020 10:04 pm
Contact:

Re: String variables passed into screen contain brackets and extra chatacters

#3 Post by GammaBreak » Tue Oct 06, 2020 4:10 pm

text _("Hair Color: " + hair_color)
Taking this verbatim causes a runtime error.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: String variables passed into screen contain brackets and extra chatacters

#4 Post by hell_oh_world » Tue Oct 06, 2020 4:14 pm

Pass the variables as they are, not as a list.

Code: Select all

call screen profile_screen(hair_color, height)
Also, might safer to use than normal concatenation...

Code: Select all

text _("Hair: {}, Height: {}".format(hair_color, height))
or...

Code: Select all

text _("Hair: [hair_color], Height: [height]")
I also suggest moving your screen definitions outside labels, they should be the same level as a normal label (0 indentation).

GammaBreak
Regular
Posts: 62
Joined: Thu Aug 06, 2020 10:04 pm
Contact:

Re: String variables passed into screen contain brackets and extra chatacters

#5 Post by GammaBreak » Tue Oct 06, 2020 4:27 pm

Okay, I think it was as you said, the call line and using the [] instead of just the variable name. Thanks!

Post Reply

Who is online

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