Random dialogue from an ever changing file?

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
xlaits
Newbie
Posts: 2
Joined: Tue Dec 15, 2009 6:25 pm
Projects: Turning a New Leaf, When You Are...
Organization: Heart & Body Games
Tumblr: xlaits
Contact:

Random dialogue from an ever changing file?

#1 Post by xlaits »

So, I'm working on a little project that essentially asks what kind of quote you want to hear, then spouts a random one from that topic to the screen.

I want to do this in a way that's easily managable, so I've opted to have an external file, essentially plaintext, that has all the quotes for one topic in it. This way, I can quickly and easily add new quotes.

However, since this file will never had a definite number of quotes, and some quotes MAY have to have multiple lines and even other dialog boxes, I am unsure how exactly to do this. Can anyone help me?

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

Re: Random dialogue from an ever changing file?

#2 Post by Ocelot »

Well, you can have additional rpy file, which would work as your external file with the addition on auto-loading and aiuto-parsing.
To solve multiple lines problem, add some structure to a file and make single quote a collection of lines:

Code: Select all

define some_quotes = [
    # Each quote is a tuple (character to say quote, list of sentenses)
    ( some_character, [
        'Line 1',
        'Line 2'
    ]),
    ( 'some name', [
        'Only line'
    ]),
]

# Usage (in another file):
init python:
    def inspirational_quote():
        char, lines = renpy.random.choice(some_quotes)
        for line in lines:
            char(line)

label quote:
    'Here is your inspirational quote for the day:'
    $ inspirational_quote()
    return
< < insert Rick Cook quote here > >

User avatar
xlaits
Newbie
Posts: 2
Joined: Tue Dec 15, 2009 6:25 pm
Projects: Turning a New Leaf, When You Are...
Organization: Heart & Body Games
Tumblr: xlaits
Contact:

Re: Random dialogue from an ever changing file?

#3 Post by xlaits »

Ocelot wrote:Well, you can have additional rpy file, which would work as your external file with the addition on auto-loading and aiuto-parsing.
To solve multiple lines problem, add some structure to a file and make single quote a collection of lines:

Code: Select all

define some_quotes = [
    # Each quote is a tuple (character to say quote, list of sentenses)
    ( some_character, [
        'Line 1',
        'Line 2'
    ]),
    ( 'some name', [
        'Only line'
    ]),
]

# Usage (in another file):
init python:
    def inspirational_quote():
        char, lines = renpy.random.choice(some_quotes)
        for line in lines:
            char(line)

label quote:
    'Here is your inspirational quote for the day:'
    $ inspirational_quote()
    return
I feel like this might be the solution I was looking for! It was a lot simpler than I thought it to be. Let me try a few things out and see what works.

EDIT:
I just noticed that this does not have ANY ability to show new character images.

Post Reply

Who is online

Users browsing this forum: No registered users