From Unicode to String for Dicts in Screens

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
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

From Unicode to String for Dicts in Screens

#1 Post by trooper6 »

Hi All,
This is such a basic simple thing...but I just can't crack it.

I have a dict. Both the Key and the Value are strings.
I want to show the keys in a box on a screen.
No matter what I do I get unicode representations: [u'sonnet'] rather than just the string "sonnet"

Here is my current tester code:

Code: Select all

default poemlist = {"sonnet": "summer"},{"haiku": "trees"}

screen poems():
    frame:
        xalign 1.0
        yalign 0.0
        vbox:
            label "Poems"
            for i in poemlist:
                text "{0!s}".format(i.keys())

# The game starts here.

label start:
    show screen poems()
    "Just testing it all out"

    return
I have tried all sorts of permutations of

Code: Select all

 text "{0!s}".format(i.keys())
and it is always the unicode object...never the string. There is clearly some sort of really obvious thing I'm missing. What's the answer here?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: From Unicode to String for Dicts in Screens

#2 Post by Remix »

text ", ".join(i.keys())
maybe
Frameworks & Scriptlets:

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: From Unicode to String for Dicts in Screens

#3 Post by gas »

If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: From Unicode to String for Dicts in Screens

#4 Post by trooper6 »

Gas, I saw that stakeoverflow page before I posted and never got to to work on a renpy screen. Have you been able to make it work? If so, I'd love to see your code.
Remix, using join worked. It feels like a workaround and not "official"--but it works so I'm happy. Thanks!
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: Google [Bot]