How do I remove brackets from displaying lists?

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
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

How do I remove brackets from displaying lists?

#1 Post by namastaii » Mon Feb 02, 2015 8:40 pm

How do I hide the brackets around any list within the game for the user interfact?

For example...

Code: Select all

screen inv_screen:
    frame:
        has vbox
        text "My inventory: [items]"
        text "Money: [money] dollars"

A simple box that shows how much money the character has and the list of items that character has in his/her inventory.

But when the interface box pops up, it shows the list like [item] or ['item', 'item']

Could someone please tell me how to type this in the code so that it doesn't show ' ' or [ ] ?

Like so:

item, item

Thank you in advance.

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

Re: How do I remove brackets from displaying lists?

#2 Post by philat » Mon Feb 02, 2015 8:47 pm

Code: Select all

$ inventory_list = ", ".join(items)
text "My inventory: [inventory_list]"
Assuming that items is the name of your list. Haven't tested how to do it exactly, but massaging some form of this should work.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How do I remove brackets from displaying lists?

#3 Post by namastaii » Mon Feb 02, 2015 11:41 pm

Nothing shows up when i do it that way.. XD
Last edited by namastaii on Tue Feb 03, 2015 3:04 pm, edited 1 time in total.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How do I remove brackets from displaying lists?

#4 Post by namastaii » Tue Feb 03, 2015 2:28 pm

It isn't really working. It just shows nothing .. lol Hm... maybe it's somthing small that is the problem.

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

Re: How do I remove brackets from displaying lists?

#5 Post by philat » Tue Feb 03, 2015 3:35 pm

I don't know what the problem is, but the following in a clean project works fine.

Code: Select all

label start:

    e "You've created a new Ren'Py game."

    e "Once you add a story, pictures, and music, you can release it to the world!"

    e "blah blah"

    $ items = ["item1", "item2"]
    $ item_list = ", ".join(items)
    "[items]\n[item_list]"
    
    show screen blah
    "blah"



screen blah():
    text "[item_list]" color "#000"

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How do I remove brackets from displaying lists?

#6 Post by namastaii » Tue Feb 03, 2015 4:56 pm

Okay, thanks I'll try again :)

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How do I remove brackets from displaying lists?

#7 Post by namastaii » Tue Feb 03, 2015 5:05 pm

Here is my example. I'm not sure if I need to take an extra step since I'm using a screen?..or maybe I'm missing something small.
I'm using this code for a contacts list for whenever the character gains a new contact in the game.

a new contact is added to contacts = [] with $ contacts.append("Amy") etc

Here is the screen:

Code: Select all

screen contacts_screen:
    frame:
        has vbox
        text "My Contacts:"
        text "[contacts_list]"
(really simple and still works.)

and here is when I define contacts_list and contacts:

Code: Select all

$ contacts = []
$ contacts_list = ", ".join(contacts)
It shows blank. Even after the contact is added to the list.

If I edit the contacts screen to show [contacts] instead of [contacts_list] then it will show my contacts like ['Amy']
I just don't really understand where the error is

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

Re: How do I remove brackets from displaying lists?

#8 Post by philat » Tue Feb 03, 2015 5:12 pm

Well, if you only define contact_lists once, then of course it's blank. You just ran ", ".join() on an empty list. You have run the method again after a new contact is added.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How do I remove brackets from displaying lists?

#9 Post by namastaii » Tue Feb 03, 2015 5:20 pm

Oh, really?

Is it every time?
or just after the first one?

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

Re: How do I remove brackets from displaying lists?

#10 Post by philat » Tue Feb 03, 2015 5:24 pm

Every time. This has to do with how variable assignments and strings work in python, so maybe google that for a more in-depth explanation.

In any case, if you don't want to run the method every time you append a new contact, you can just as easily define a function to do it for you.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How do I remove brackets from displaying lists?

#11 Post by namastaii » Tue Feb 03, 2015 5:25 pm

Okay, thank you.

I actually know a fair amount of Python and just ..didn't know about this

I'll probably define a function. Good idea.
Thank you :)

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: How do I remove brackets from displaying lists?

#12 Post by trooper6 » Tue Feb 03, 2015 6:06 pm

Based on a bit of something in my own code, I did this and it works. No functions needed:

Code: Select all

init python:
    contact_list = []
screen contacts_screen():
    frame:
        has vbox
        text "My Contacts:"
        for item in contact_list:
           text ("[item]")
           
# The game starts here.
label start:
    show screen contacts_screen
    "The list should be empty."
    $ contact_list.append("Jane")
    "Just added Jane"
    $ contact_list.append("John")
    "Just added John"
But I'm also interested in these new screen variables...so I tried this, which also works:

Code: Select all

screen contacts_screen(title, list):
    frame:
        has vbox
        text "[title]"
        for item in list:
           text ("[item]")
           
# The game starts here.
label start:
    $ friend_list = []
    $ enemy_list = []
    show screen contacts_screen("Friends:", friend_list)
    "I'm showng an empty friend list."
    $ friend_list.append("Jane")
    "Just added Jane"
    $ friend_list.append("John")
    "Just added John"
    show screen contacts_screen("Enemies:", enemy_list)
    "I'm showng an empty enemy list."
    $ enemy_list.append("Muffy")
    "Just added Muffy"
    $ enemy_list.append("Brad")
    "Just added Brad"  
No special functions needed. Hope that might be helpful!
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

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

Re: How do I remove brackets from displaying lists?

#13 Post by philat » Tue Feb 03, 2015 6:17 pm

trooper6's method produces the names printed in a box without punctuation. As far as I know, there's no easy way to format the result of a for loop to produce a string that looks like "Item 1, Item 2, Item 3", etc. OTOH, if you don't really care about the formatting, a for loop is a perfectly valid way to put the contents of a list on a screen.

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: How do I remove brackets from displaying lists?

#14 Post by trooper6 » Tue Feb 03, 2015 6:47 pm

I didn't deal with the comma issue because I realized that since the screen is a vbox, each entry is on its own line, so the comma didn't seem necessary. I also didn't really like the aesthetics of it with the comma. But, if you want the comma, do this:

Code: Select all

screen contacts_screen(title, list):
    frame:
        has vbox
        text "[title]"
        $i = len(list)
        for item in list:
            if i == 1:
                text ("[item]")
            else:
                text ("[item],")
            $i -= 1
           
# The game starts here.
label start:
    $ friend_list = []
    $ enemy_list = []
    show screen contacts_screen("Friends:", friend_list)
    "I'm showng an empty friend list."
    $ friend_list.append("Jane")
    "Just added Jane"
    $ friend_list.append("John")
    "Just added John"
    $ friend_list.append("Gertude")
    "Just added Gertrude"
    
    show screen contacts_screen("Enemies:", enemy_list)
    "I'm showng an empty enemy list."
    $ enemy_list.append("Muffy")
    "Just added Muffy"
    $ enemy_list.append("Brad")
    "Just added Brad" 
Or if you don't want to use screen variables:

Code: Select all

init python:
    contact_list = []

screen contacts_screen():
    frame:
        has vbox
        text "Contacts:"
        $i = len(contact_list)
        for item in contact_list:
            if i == 1:
                text ("[item]")
            else:
                text ("[item],")
            $i -= 1
           
# The game starts here.
label start:
    show screen contacts_screen()
    "I'm showng an empty contact list."
    $ contact_list.append("Jane")
    "Just added Jane"
    $ contact_list.append("John")
    "Just added John"
    $ contact_list.append("Gertude")
    "Just added Gertrude"
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

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

Re: How do I remove brackets from displaying lists?

#15 Post by philat » Tue Feb 03, 2015 7:02 pm

Yeah, you could do it using some sort of counter but I just find them kind of annoying lol. I use them if I have to. ;)

You could also use a for i in range(len(contact_list)) loop to use index numbers and get around using a separate counter if you really wanted to.

But anyway, I was referring to the OP's set up, which would ideally produce something like this:

My items: item1, item 2, item 3
Money: X dollars

If you're married to this particular presentation, I still think .join() is cleaner and simpler. On the other hand, if it's for a contacts list in a phone, a straight up vbox presentation of the list is probably better in the first place. So, ymmv.

Post Reply

Who is online

Users browsing this forum: Google [Bot]