List keeps outputting u between strings? (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
User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

List keeps outputting u between strings? (solved)

#1 Post by noeinan »

I've been writing a class to help generate random npcs for my game, but when I'm testing out the class traits that are lists show up as u"string", u"string" instead of string, string. I'd like to display the individual parts of the list in text without the u and quotations showing up, but I'm not sure how to do that?

Here's the bit where I'm displaying the line:

Code: Select all

label start: 
    $ racelist = ["human", "elf", "gnome"]
    $ typelist = ["student", "coworker", "stranger"]
    $ procaselist = ["m", "f", "t", "i", "n"]
    $ buildlist = ["ripped", "emaciated"]
    
    "This is a test."
    
    $npc = NPCList(racelist, typelist, procaselist, buildlist, 1)
    
    "Build Desc: [npc.builddesc]"
And here's how it's adding to the string in my class:

Code: Select all

init python:
    enemyno = 0

    class NPCList():

        def __init__(self, racelist, typelist, procaselist, buildlist, level):

            global enemyno

            if enemyno < 5:
                enemyno += 1
                self.num = enemyno
            elif enemyno == 6:
                self.num = enemyno
            else:
                self.num = 0

            self.race = renpy.random.choice(racelist) #Random race as determined by the area

            if self.race == "human" or self.race == "elf":
                self.racesize = 2
            elif self.race == "gnome":
                self.racesize == 1
            else:
                self.racesize == 0



            self.type = renpy.random.choice(typelist) #Context description, like classmate or coworker or stranger

            prorng = renpy.random.randint(1,100)

            if nbchance >= prorng:
                self.procase = "t"
            elif wchance < nbchance and wchance > prorng:
                self.procase = "f"
            elif mchance < nbchance and mchance < wchance and mchance > prorng:
                self.procase = "m"
            else:
                self.procase = renpy.random.choice(procaselist)

            self.builddesc = []
            genrng = renpy.random.randint(1,100)
            
            if twchance >= genrng and self.procase == "f":
                self.builddesc.append("curvy")
            elif self.procase == "f":
                self.builddesc.append("stocky")
            elif tmchance >= genrng and self.procase == "m":
                self.builddesc.append("bulky")
            elif self.procase == "m":
                self.builddesc.append("slender")
            else:
                self.builddesc.append(renpy.random.choice(buildlist))

            self.level = level

later in the code I have the option to add extra descriptions based on certain variables, again just using .append (which is why it's a list and not just a string).


Googling around, it seems like this has something to do with unicode vs ascii vs utf-8? I admit this is new to me so I'm not terribly educated on the topic.
https://stackoverflow.com/questions/977 ... -u-in-list
Last edited by noeinan on Wed Apr 08, 2020 10:48 am, edited 1 time in total.
Image

Image
Image

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: List keeps outputting u between strings?

#2 Post by philat »

Didn't read the whole thing as this is probably just a matter of how you're outputting the list.

Code: Select all

default list1 = ["a", "b", "c"]

label start:
    "[list1]" # simply printing shows the list directly (even without the u', you'd still be getting ["a", "b", "c"] which probably isn't what you'd want
    "[list1[0]]" # accessing any element directly prints normally
    $ temp = ", ".join(list1) # you can use .join() (google for more details) to output list as one string
    "[temp]"

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: List keeps outputting u between strings?

#3 Post by Remix »

You could smuggle the ", ".join(sequence) bit into your class ...

Code: Select all

            else:
                self.builddesc.append(renpy.random.choice(buildlist))

            self.builddesc_str = ", ".join(self.builddesc)
(or overwrite self.builddesc itself. Perhaps even use the __str__ or __repr__ methods of the class to do the same)
Frameworks & Scriptlets:

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: List keeps outputting u between strings?

#4 Post by noeinan »

Thanks for the advice, that seems to work!
Image

Image
Image

Post Reply

Who is online

Users browsing this forum: No registered users