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.
Message
Author
renpyhelp
Regular
Posts: 71
Joined: Tue Feb 27, 2018 2:01 am
Contact:

Scrollable automatic journal entries?

#1 Post by renpyhelp »

Thanks to remix's help I was able to have an in-game text system via pictures with this code:

Code: Select all

default conversations = [] # once a convo is unlocked, we append it to this list

screen a():
    vbox:
        for k in conversations: # iterate the list in correct order
            text "convo_{}".format( k )

label start:
    show screen a
    $ conversations.append(2)
    "..."
    $ conversations.append(1)
    "..."
I'm now wondering if I could use the same system for automatic journal entries?
Instead of using pictures, I could use simple text within game (to save space). Is that even possible?

Example:
play wakes up tuesday morning -> activates journal entry -> journal entry displays "It's been a great tuesday morning!" and you are able to scroll through past entries.

I could do this via pictures to $ .append, but would really like to avoid that if possible.

Hope that makes enough sense.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Scrollable automatic journal entries?

#2 Post by kivik »

You can do this with a viewport:

https://www.renpy.org/doc/html/screens.html#viewport

I'm guessing yinitial 1.0 will make it start at the bottom.

User avatar
IaMe
Regular
Posts: 31
Joined: Fri Jan 11, 2013 5:27 am
Location: Australia
Contact:

Re: Scrollable automatic journal entries?

#3 Post by IaMe »

I think what you are trying to do is change the code you have with pictures to use text instead?
and it seems like the original code you got here viewtopic.php?f=8&t=49186&p=483621#p483614 that I found through a quick search.
... change the -- text image_ref -- to -- image image_ref -- I used text for quick test this comment makes it seems like if you just switch that bit of code back and swap the stored images with stored snippets of text (you'll need to play around and figure that bit out ^^) you should probably manage to get it to work?
Am just flexing my thinking muscles here though but hopefully it helps somehow!
The Website for my game's development
http://fallingheartsotomegame.tumblr.com/

User avatar
IaMe
Regular
Posts: 31
Joined: Fri Jan 11, 2013 5:27 am
Location: Australia
Contact:

Re: Scrollable automatic journal entries?

#4 Post by IaMe »

and I finally found the other thing I was looking for viewtopic.php?f=51&t=25281 perhaps this will also be helpful somehow? I don't know just trying to help out some! anyway hopefully you can get it working!!!
The Website for my game's development
http://fallingheartsotomegame.tumblr.com/

renpyhelp
Regular
Posts: 71
Joined: Tue Feb 27, 2018 2:01 am
Contact:

Re: Scrollable automatic journal entries?

#5 Post by renpyhelp »

I completely forgot the original code posted used text instead of an image! I’ll defintely try that tonight. Thank you much!

renpyhelp
Regular
Posts: 71
Joined: Tue Feb 27, 2018 2:01 am
Contact:

Re: Scrollable automatic journal entries?

#6 Post by renpyhelp »

Update:
I use this code for the journal entry, but it doesn't work quite right.

Code: Select all

        background "transparent.png"    # or use any semi-transparent image you like
        
        side "c r":
            area (365, 157, 557, 437)

            viewport id "vp":
                draggable True

                vbox:
                    for k in m_journal: # iterate the list in correct order
                        text "This is the first journal entry"
                        text "This is the second journal entry"
When doing "$m_journal.append(1)" or "$m_journal.append(2)" it just posts both text entries listed and in the order listed within the code.
I just need to be able to activate which line of text gets added to the viewport and have them shown in the order I added them in. The image code I used works great, but I just can't figure it out with text only.

User avatar
IaMe
Regular
Posts: 31
Joined: Fri Jan 11, 2013 5:27 am
Location: Australia
Contact:

Re: Scrollable automatic journal entries?

#7 Post by IaMe »

viewtopic.php?f=8&t=49360 could this help??? seems like they figured out a similar function too what you are after or I hope so anyway!!! otherwise hopefully someone else will come along and be able to help you figure it out better that I have ^^ I did have fun looking around for code snippets and hopefully I was at least a bit useful with my digging :D. Anyway good luck with your coding too!!!
The Website for my game's development
http://fallingheartsotomegame.tumblr.com/

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Scrollable automatic journal entries?

#8 Post by kivik »

Your code doesn't actually reference k in the loop - so it'll loop through the m_journal however many times its length, and output the text "This is the first journal entry" "This is the second journal entry".

If m_journal is a list of strings, then just put:

Code: Select all

for k in m_journal:
    text k
I think that's what you mean by your comments.

renpyhelp
Regular
Posts: 71
Joined: Tue Feb 27, 2018 2:01 am
Contact:

Re: Scrollable automatic journal entries?

#9 Post by renpyhelp »

kivik wrote: Wed Apr 25, 2018 5:28 am Your code doesn't actually reference k in the loop - so it'll loop through the m_journal however many times its length, and output the text "This is the first journal entry" "This is the second journal entry".

If m_journal is a list of strings, then just put:

Code: Select all

for k in m_journal:
    text k
I think that's what you mean by your comments.
A bit confused by this. Basically just want each line of text to be added to the viewport in the order I want them to be.
So say the 2nd journal entry is to come first, I "$ m_journal.append(2)" and that one will come first within the list. Then once I add the first journal entry, it'll be UNDER the second journal entry.
Hope that explains it a bit better.

Currently when I do "$ m_journal.append(2)" it puts both line of text within the viewport.

The journal entries are to be listed depending on what the player does first.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Scrollable automatic journal entries?

#10 Post by kivik »

Sorry I saw this in your code:

Code: Select all

for k in m_journal: # iterate the list in correct order
    text "This is the first journal entry"
    text "This is the second journal entry"
So I thought you weren't using the k in your for loop and was hard coding the text inside (first journal entry, second journal entry). Are you using the same code as your first post in that case?

Code: Select all

for k in conversations: # iterate the list in correct order
    text "convo_{}".format( k )
I think I understand the idea that you want first item in your list to come first - and by first I assume you mean top? It's strange that your list is coming back inverted, but I think I need to see actual code snippets (not abstract code examples) in order to know for sure where the problem is. It could actually be that your game flow added the journal entries the wrong way around, it could be that your screen code has gone weird.

In fact I just did a very basic test and it shows in order for me... so definitely need to see actual screen code and your game flow to know for sure.

One way you can check whether the append is happening in the correct order is to add a debug statement:

Code: Select all

$ print('adding journal entry 1')
Then open console with Shift-O to see what gets printed first.

renpyhelp
Regular
Posts: 71
Joined: Tue Feb 27, 2018 2:01 am
Contact:

Re: Scrollable automatic journal entries?

#11 Post by renpyhelp »

What I meant was that I want the text to be displayed in the order I manually append it. So it can be put in any order. So if there was 5 entries, it could be put as 5/3/2/4/1, 1/2/5/3/4, etc.

Here is the full code I currently use

Code: Select all

    frame:
        background "transparent.png"    
        
        side "c r":
            area (365, 157, 557, 437)

            viewport id "vp":
                draggable True

                vbox:
                    for k in m_journal: 
                        text "This is the first journal entry"
                        text "This is the second journal entry"
                        text "This is the third journal entry"
                        text "This is the fourth journal entry"
                        text "This is the fifth journal entry"
When activated to be added to the viewport, I want to be able to put these in order of activation. Currently it just adds all lines of text when I .append it. I want each journal entry added to the viewport at seperate times and the order I put them in from top to bottom.

It already works for images with this code:

Code: Select all

    frame:
        background "transparent.png"  
        
        side "c r":
            area (546, 161, 298, 480)

            viewport id "vp":
                draggable True

                vbox:
                    for k in girl_convo: # iterate the list in correct order
                        image girl_convo_{}".format( k )
This puts any image I have with name girl_convo_# to be put in the viewport by adding girl_convo.append(#). They are they in the order I appended them.

Essentially I want the exact same as the image variation, but with text instead.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Scrollable automatic journal entries?

#12 Post by kivik »

Can I clarify - do you know how for loops work in python? Sorry if it comes across the wrong way, I think maybe I'm not understanding where you're coming from, from a non-coder background and thus what I said wouldn't have made any sense!


In fact I'm going to rewrite my earlier answer in more detail on the assumption that you are unfamiliar with programming. I apologise if it comes across patronising, but I just want to make sure you get the answer you need!


Your code doesn't use the k variable in the for loop, so it'll just output whatever you've put inside the for loop block as many times as you have items in the m_journal list variable. Because you've physically put 5 lines of text inside the block (none of them uses the variable k, which is supposed to hold the journal entry), and the block is just repeating as many times as there are journal entries, with k (in theory) holding the current journal entry.

Notice how there's only one line in remix's code? And it uses the k variable to substitute what's inside:

Code: Select all

for k in conversations:
    image "convo_{}".format(k)
What's happening there is the code loops through the conversations variable, which is a list - so it'll loop through it as many times as there are conversations. On each loop, it'll take the content of that particular list entry, and put it in k.

So let's say the list is [1,5,3]. First time it runs through the loop, k == 1; second loop, k == 5; third loop k == 3.

The second line of code basically says display an image here based on the following string: "convo_{}".format(k)". The {} gets replaced with what's inside format - which is k, which is 1, 5 and 3 on the corresponding loop. So the outputs will be:
"convo_1", "convo_5", "convo_3".

Note: the "string".format(k) code is used because k is an int (integer) and cannot be concatenated to a string in python, so it formats k into a string before putting it .

So to duplicate the effect, we want to keep the for loop, change the image into text, and think about what k contains. From your examples, k only contains alpha-numerals; 1, 2, 3, 4, 5 etc. It doesn't contain the actual diary entry - so you can't magically make your text read out the diary entry. The best you can get it to do is:

Code: Select all

text "This is the journal entry {}".format(k)
which will give you at best, in the [1,5,3] example:
This is the journal entry 1
This is the journal entry 5
This is the journal entry 3

If you want your screen to actually display the journal entry - you have two options. You either actually put the journal entry into your m_journal list - a list can contain any type of variables, including strings!

So you'd do something like this during the game flow:

Code: Select all

$ m_journal.append("This is the first journal entry")
$ m_journal.append("This is the fifth journal entry")
$ m_journal.append("This is an entry about monkeys hating citrus fruit for no reason")
And this in your screen:

Code: Select all

for k in m_journal:
    text k
It'll just output whatever you actually appended in the list.

There are other ways of doing this, including a way that uses int (by using python dicts), but if you're unfamiliar with coding, it may be best for another day.

I hope this makes more sense and answers your question! Reading back I think I focused on what you said about order and thought you're saying that your code isn't showing things in the right order. I thought you were showing us sort of pseudo codes instead of actual code - which is my bad assumption.

One thing that could help clarifying when asking programming questions is:

What is your input?
What is your expected output?
What is the output you actually got? - this part you just described in English and it's why I ended up misunderstanding.

renpyhelp
Regular
Posts: 71
Joined: Tue Feb 27, 2018 2:01 am
Contact:

Re: Scrollable automatic journal entries?

#13 Post by renpyhelp »

Ah! That is exactly what I needed! I didn't know you could append text through simple quotes like that. Works great! I am still learning renpy and very new to coding in general, but I do what I can. You're extensive help has eased a lot of headache. Thank you SO very much kivik.

EDIT: Cancel the question below [journal_entry_number] displays it!
One last question, if you can answer it. Would the append statement be able to write a number in depending on a variable? What I mean is by this code:

Code: Select all

$ m_journal.append("{color=#000000}Journal Entry #NUMBER{/color}")
if "$ journal_entry_number == 5", could I have the place that currently says NUMBER be written as 5? As the variable changes and the code is re-put into the viewport, the NUMBER will be whatever the variable amount is. Hope that makes sense.

renpyhelp
Regular
Posts: 71
Joined: Tue Feb 27, 2018 2:01 am
Contact:

Re: Scrollable automatic journal entries?

#14 Post by renpyhelp »

Looks like [journal_entry_number] updates the previous Journal Entries to the same number.
So each entry is displayed as #3 if the variable is 3

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Scrollable automatic journal entries?

#15 Post by kivik »

No problems at all! Sorry it's hard to tell people's programming experience on here sometimes, and there's a risk of being far too detailed and coming across patronising, or in this case not detailed enough assuming the person knows what we're talking about when answering questions!


For the above: I'm going to assume this is what you want your output to be:

If the entries are: "I saw a butterfly!" "A dog peed on my window..." "A bird landed on my shoulder today"
And you got them in this order: [dog, bird, butterfly]
The output will be:

Journal Entry 1
[Dog]
Journal Entry 2
[Bird]
Journal Entry 3
[Butterfly]

i.e. Whatever order you append the entries, you want the output to be 1, 2, 3 in order.


If that's the case, the easiest way is probably to do this when you append the journal entry number:

Code: Select all

$ m_journal.append("{color=#000000}Journal Entry #{}{/color}".format(journal_entry_number))
$ journal_entry_number += 1
The reason this works and "{color=#000000}Journal Entry #[journal_entry_number]{/color}" doesn't, is that the above version resolves the variable value before the string is appended to the list by the python code. So what ends up being appended is "{color=#000000}Journal Entry #1{/color}", "{color=#000000}Journal Entry #2{/color}", "{color=#000000}Journal Entry #3{/color}"

Meanwhile "[journal_entry_number]" - the way you put a variable inside square brackets, is not resolved by python - it's a Ren'py specific way of displaying variables - at the point of render. So if you have [variable_name], it's only when Ren'py renders the text on screen that it works out its value, and as such it'll always render the latest version of the value - 3 if you've added 3 journal entries.

This can be a bit hard to understand at first, but it will become easier over time when you understand what's Ren'py, what's python, and how the two languages talk to each other. I hope the above makes sense and can help you in the future!

Post Reply

Who is online

Users browsing this forum: No registered users