Scrollable automatic journal entries?

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.
Posts: 46
Joined: Tue Feb 27, 2018 2:01 am

Re: Scrollable automatic journal entries?

#16 Post by renpyhelp » Thu Apr 26, 2018 7:36 am

I figured out a way, though it might not be the cleanest way possible.

I essentially have a variable gain += every time a journal entry is added. Then during the call I have this code:

Code: Select all

    if journal_count == 1:
        $ journal.append("{color=#000000}{b}Journal Entry #1{/b}{/color} {space=15} {color=#D60000}{b}Journal Entry Title{/b}")
    elif journal_count == 2:
        $ journal.append("{color=#000000}{b}Journal Entry #2{/b}{/color} {space=15} {color=#D60000}{b}Journal Entry Title{/b}")
    elif journal_count == 3:
        $ journal.append("{color=#000000}{b}Journal Entry #3{/b}{/color} {space=15} {color=#D60000}{b}Journal Entry Title{/b}")
I then add more elif's as I produce more journal entries. Works like a charm in game, but of course, takes up a lot more space.

Miko-Class Veteran
Posts: 519
Joined: Fri Jun 24, 2016 5:58 pm

Re: Scrollable automatic journal entries?

#17 Post by kivik » Thu Apr 26, 2018 9:44 am

Why don't you add a label like this:

Code: Select all

label add_journal(journal_entry_title):
    $ journal.append("Journal Entry #{}".format(len(journal)+1) + "  {space=15}  " + journal_entry_title)
I've removed the font styling because you can do that on your screen using text styling, so it's silly to hard code it in.

Now if you want to add a journal entry, just do this:

Code: Select all

call add_journal("This is an entry")
call add_journal("This is another entry")
Here's how it works:

The label takes a parameter - the actual journal title which depends on what you add. The journal entry number we can work out programmatically so we won't pass it as a parameter. Once inside the label, the variable journal_entry_title becomes whatever text you pass in.

Code: Select all

label add_journal(journal_entry_title):
Next the append, let's break it down. First let's go back to what we talked about before - using string.format() to add a number into your final string:

Code: Select all

"Journal Entry #{}".format(len(journal)+1)
This is the same as what we had before: {} inside the string gets substituted with whatever is inside the format() function.

What is len(journal)+1 then?

Well len() can work out the length of a list, so we're putting our journal list in. So if your list is empty, len(journal) returns 0. Well we want the first entry to start at 1, so we'll add 1 to it. So now when there's 0 journal entry, len(journal)+1 returns 1; 1 entry it returns 2; etc. Exactly what we want going forward. It doesn't matter how many entries we put in, it'll work it out automatically.

So combining the two part, we have a string that will become "Journal Entry #1" for entry 1, #2 for entry 2 and so forth.

Finally, we'll combine everything together in our append statement, we add the spacing because that can't be influenced by the screen text styling. We're essentially adding:

"Journal Entry #1 {space=15} [whatever you put into the parameters]"

So for the example above, it'll create a list with:

call add_journal("This is an entry
Journal Entry #1 {space=15} This is an entry
Journal Entry #2 {space=15} This is another entry

Onto formatting your text on the screen. You apply text styling: ... properties

Code: Select all

for k in journal:
    text k color "#000" bold True
That should output exactly what you need.

Post Reply

Who is online

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