[Solved] Problem calling list items in dialogue.

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
Ferrous Ferret
Newbie
Posts: 5
Joined: Thu Mar 21, 2019 10:08 pm
Contact:

[Solved] Problem calling list items in dialogue.

#1 Post by Ferrous Ferret »

Greetings,

I've been playing around with ren'py for a while now and have had a reoccurring problem with lists. I've usually been able to work around it or ignore it, but my latest project requires lists to be practical. So I'm hoping someone can help me with my (probably simple) problem.

Whenever I call an item from a list in dialogue it is displayed as [u'item name']. For example;

Code: Select all

init:     
    $ animal  = ['bunnies', 'kitties', 'doggies', 'ponies']
    $ number  = [2, 3, 4, 5]

label animal_intro:
    $ animal_select = renpy.random.sample(animal, 1)
    $ number_select = renpy.random.sample(number, 1)
    e "Aww, it's [number_select] adorable [animal_select]."
                        
is shown in game as:
Aww it's [u'3'] adorable [u'kitties'].

I feel there has to be a way to select items from lists without the [u' '], but I can't figure out how. Any help would be greatly appreciated, thanks in advance!
Last edited by Ferrous Ferret on Fri Mar 22, 2019 3:52 pm, edited 1 time in total.

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: Problem calling list items in dialogue.

#2 Post by Remix »

Add [0] to the sample() calls...

$ animal_select = renpy.random.sample(animal, 1)[0] ## <--- the first item of the returned random choice

For clarity, the sample function always returns a set or list of items, so we specify that we just want the first one as our value
Frameworks & Scriptlets:

Ferrous Ferret
Newbie
Posts: 5
Joined: Thu Mar 21, 2019 10:08 pm
Contact:

Re: Problem calling list items in dialogue.

#3 Post by Ferrous Ferret »

It works perfectly! Thank you so much.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]