[SOLVED] Making a character say a random element from a list

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
Team1Player2
Newbie
Posts: 9
Joined: Tue Mar 29, 2022 4:01 am
Contact:

[SOLVED] Making a character say a random element from a list

#1 Post by Team1Player2 » Sun Oct 09, 2022 3:37 pm

Hello,

I am trying to build a dialogue system in which one option is "Small talk". It improves relationship by a small value and gives random bits of dialogue. Mechanically, each character has several relationship states. Those are lists. I already wrote code that deletes and adds names to the appropriate list based on relationship. Each relationship level has a corresponding list of small talk.

Code: Select all

def choose_small_talk(name):
        if name in met_not_acquainted:
            small_talk = renpy.random.choice(adam_small_talk_1)
            
a "here will be the random thing"
How do I make my characters say the random nonsense picked from that list?
Last edited by Team1Player2 on Sun Oct 09, 2022 5:18 pm, edited 1 time in total.

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1882
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Making a character say a random element from a list

#2 Post by Ocelot » Sun Oct 09, 2022 4:54 pm

Code: Select all

# We are returning chosen sentence instead of setting local variable
def choose_small_talk(name):
    if name in met_not_acquainted:
        return renpy.random.choice(adam_small_talk_1)
    return renpy.random.choice(adam_small_talk_0)

# . . .

# You can use either:
$ a( choose_small_talk("some_name") )

# or this, if you want to process it before displaying
$ small_talk = choose_small_talk("some_name") 
$ a( small_talk )
< < insert Rick Cook quote here > >

Team1Player2
Newbie
Posts: 9
Joined: Tue Mar 29, 2022 4:01 am
Contact:

Re: [SOLVED] Making a character say a random element from a list

#3 Post by Team1Player2 » Sun Oct 09, 2022 5:32 pm

Thank you. Works as intended.

Post Reply

Who is online

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