Journal System for RenPy Games (& Python in Screen Language)

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
sciencewarrior
Veteran
Posts: 356
Joined: Tue Aug 12, 2008 12:02 pm
Projects: Valentine Square (writer) Spiral Destiny (programmer)
Location: The treacherous Brazilian Rainforest
Contact:

Re: Journal System for RenPy Games (& Python in Screen Langu

#16 Post by sciencewarrior »

Code: Select all

  
        "X" [part1] [part2] [part3], 
should be:

Code: Select all

  
        "X [part1] [part2] [part3]", 
Keep your script in your Dropbox folder.
It allows you to share files with your team, keeps backups of previous versions, and is ridiculously easy to use.

TrickWithAKnife
Eileen-Class Veteran
Posts: 1261
Joined: Fri Mar 16, 2012 11:38 am
Projects: Rika
Organization: Solo (for now)
IRC Nick: Trick
Location: Tokyo, Japan
Contact:

Re: Journal System for RenPy Games (& Python in Screen Langu

#17 Post by TrickWithAKnife »

Wow, I really should have noticed that. Thanks a lot to everyone who helped!
"We must teach them through the tools with which they are comfortable."
The #renpy IRC channel is a great place to chat with other devs. Due to the nature of IRC and timezone differences, people probably won't reply right away.

If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.

Roxie
Regular
Posts: 71
Joined: Sat Aug 13, 2011 9:07 pm
Projects: Assess K, Mizuchi
Organization: Aikasa Collective, Altabe Studio
itch: aikasacolle
Location: Southern California
Contact:

Re: Journal System for RenPy Games (& Python in Screen Langu

#18 Post by Roxie »

This code has been very helpful :) I'm still a beginner with coding so I was wondering about something. If we wanted to show a big body of text (instead of breaking it down to multiple pages), I've noticed it gets cut off once it reaches the bottom, making the remaining text unable to be seen. Is it possible to add a vertical scrollbar? Also, what if we wanted to add a picture to the page is that feasible?

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: Journal System for RenPy Games (& Python in Screen Langu

#19 Post by apricotorange »

You can make scrollable views in a screen with "viewport"; see http://www.renpy.org/doc/html/screens.html#viewport .

You can add images to a screen with "add"; see http://www.renpy.org/doc/html/screens.html#add .

Roxie
Regular
Posts: 71
Joined: Sat Aug 13, 2011 9:07 pm
Projects: Assess K, Mizuchi
Organization: Aikasa Collective, Altabe Studio
itch: aikasacolle
Location: Southern California
Contact:

Re: Journal System for RenPy Games (& Python in Screen Langu

#20 Post by Roxie »

Yeah the viewport doesn't come out right when I try to merge both the codes together. It doesn't scroll at all, and for some reason it has left/top side scrollbars instead of the usual right/bottom scrollbars. I've attached the screenshot of the error. Also whenever I try to do the "add" image statement in the list it doesn't work. I'm guessing it's some other format?

Code: Select all

#############################################################################
## Variables and Functions
##
## This block of code contains all of the variables and functions required to
## get the screens to work.

init -2 python:
    date_ref = ""
    time_ref = ""
    loc_ref = ""

    current_journal_page = 3 # The curent page of the journal
    unlocked_journal_pages = 5 # of pages unlocked
    #### The contents of the journal pages
    ## This is a list of the contents of the journal pages.  The first
    ## item in the list, in this case "X", is in position 0, so your
    ## current journal page, which is set to zero, points to this location.
    ## For the sake of easy programming, define all of your journal pages
    ## before-hand.  Otherwise, you have to deal with inserting them and
    ## nonesense like that, which is sort of painful until you get the
    ## hang of doing it.

    journal_entries = list([
        "X", 
        "Test - In 1891, London detective Sherlock Holmes (Robert Downey, Jr.) and his partner and flatmate Dr. John Watson (Jude Law) race to prevent the ritual murder of a woman by Lord Blackwood (Mark Strong), who has killed five other young women similarly. They stop the murder before Inspector Lestrade (Eddie Marsan) and the police arrive to arrest Blackwood. Three months later, Holmes' eccentric behavior again annoys Watson. (Long snippet from Wiki summary)",
        "Y",
        "Z",  # What is the code to add bird image to this list?
        "A",
        "B",
        "C",
        ])
    
    #### The increment function
    ## This is what you put after your "action" keyword
    class incrementJournal():
        ## This defines what happens when the class is called
        ## (as in, when you click the button)
        def __call__(self):
            ## Gotta use the "global" keyword to use any variable
            ## outside your function, as it's a quirk of Python 
            global current_journal_page
            ## Increment the counter variable which keeps track of
            ## which journal page is currently active
            current_journal_page += 1
            ## Restart the interaction to refresh your screen
            renpy.restart_interaction()
        
    #### The decrement function
    ## Exactly the same as above, only you decrement the
    ## counter variable, instead of incrementing it.
    class decrementJournal():
        def __call__(self):
            global current_journal_page
            current_journal_page -= 1
            renpy.restart_interaction()
        
    #### The void function
    ## A void function that I like to use to block out buttons
    def void():
        ## Do something that won't affect the rest of the game
        DummyVariable = 0


##############################################################################
# Journal
#
# Displays the log of notes.

screen journal_screen:
    tag menu
    imagemap:
            ground "j_idle.png"
            idle "j_idle.png"
            hover "j_hover.png"
    
            if current_journal_page < (unlocked_journal_pages - 1):
                hotspot (588, 23, 94, 50) action incrementJournal()
            else:
                hotspot (588, 23, 94, 50) action void()

            if current_journal_page >= 1:
                hotspot (463, 23, 94, 50) action decrementJournal()
            else:
                hotspot (463, 23, 94, 50) action void()
             
            side "c b r":
                area (100, 100, 300, 300)

                viewport id "vp":
                    draggable True

                    text (journal_entries[current_journal_page])

                    bar value XScrollValue("vp")
                    vbar value YScrollValue("vp")


init -2 python:
    style.pref_frame.xfill = True
    style.pref_frame.xmargin = 5
    style.pref_frame.top_margin = 5

    style.pref_vbox.xfill = True

    style.pref_button.size_group = "pref"
    style.pref_button.xalign = 1.0

    style.pref_slider.xmaximum = 192
    style.pref_slider.xalign = 1.0

    style.soundtest_button.xalign = 1.0
Attachments
Error
Error

User avatar
saguaro
Miko-Class Veteran
Posts: 560
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Organization: Lucky Special Games
itch: saguarofoo
Location: USA
Contact:

Re: Journal System for RenPy Games (& Python in Screen Langu

#21 Post by saguaro »

Code: Select all

            side "c b r":
                area (100, 100, 300, 300)

                viewport id "vp":
                    draggable True

                    text (journal_entries[current_journal_page])

                bar value XScrollValue("vp")
                vbar value YScrollValue("vp")
The scroll bars are indented too far.
Also whenever I try to do the "add" image statement in the list it doesn't work. I'm guessing it's some other format?
I haven't tested this but I would try an image tag:

Code: Select all

"{image=imagename.png}"
http://www.renpy.org/doc/html/text.html ... -text-tags

Roxie
Regular
Posts: 71
Joined: Sat Aug 13, 2011 9:07 pm
Projects: Assess K, Mizuchi
Organization: Aikasa Collective, Altabe Studio
itch: aikasacolle
Location: Southern California
Contact:

Re: Journal System for RenPy Games (& Python in Screen Langu

#22 Post by Roxie »

Thanks Saguaro :D Worked perfectly now on both counts.

One last question, how does one update the unlocked_journal_pages during gameplay script?
ImageImage
Assess K (VN Adventure Game) LSF Thread | Mizuchi (GxG VN) LSF Thread | Honest Critique
[Proofreader, Beta-Tester]
Razz Art Visual - Starlight Vega [Co-writer]
Roseverte - Cafe-0, Duplicity, East Tower, How to Take Off Your Mask; Bakufu - Love Sniper
Zeiva Inc. - Train of Afterlife, OASE, X-Note, Area-X, Voices from the Sea, Natural - Beyond Nature, Dragon Essence, Anicon - Cat

User avatar
saguaro
Miko-Class Veteran
Posts: 560
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Organization: Lucky Special Games
itch: saguarofoo
Location: USA
Contact:

Re: Journal System for RenPy Games (& Python in Screen Langu

#23 Post by saguaro »

You just need to update the variable to reflect the new total of pages at the appropriate spot in the script. $ denotes a python statement.

e.g.
$ unlocked_journal_pages = 10

hatsuka
Newbie
Posts: 3
Joined: Thu May 24, 2012 3:28 pm
Contact:

Re: Journal System for RenPy Games (& Python in Screen Langu

#24 Post by hatsuka »

This is probably a total noob error, but... =.=
I'm having some trouble with the code. It's saying something about an expected language screen statement. I've only been using renpy for a few months so it's probably a really obvious solution, but I have no idea what I'm doing...

http://gyazo.com/c3fe311ab17e4ded0616ffba8c52c138

I feel like such an idiot right now... =___=;; I'm sorry if this is a really dumb question to be asking, but... any help at all would be greatly appreciated ; n ;

User avatar
Kate
Regular
Posts: 197
Joined: Thu Sep 19, 2013 6:10 pm
Projects: Blackout
Organization: Moonlight Otome
Location: United States
Contact:

Re: Journal System for RenPy Games (& Python in Screen Langu

#25 Post by Kate »

I've figured out how to put text in a journal entry; but I don't know how to call up the journal entry in the script (like when a character gives you a clue) - how to unlock it in the script?- and how to show the screen that will display the journal entry. Is it a text box I have to specify and then pull up (like the fullscreen example used by Roxie with the images?)?

Also, if I want the journal entries to remain present when unlocked on the side of the screen in a vertical column over a text box, can I do that? Sort of like the checklist in the nancy drew pc games...

Also, I love it when the helpful users kindly define what certain repeated symbols or keywords do, like the explanation of $. Gives noobs like me fewer headaches that way! Many thanks.
Current Project:
Blackout [VN][Romance][GxB][Mystery][Suspense] http://lemmasoft.renai.us/forums/viewto ... 43&t=34118
"It is the duty of authors to make the fantastic seem ordinary and the ordinary seem fantastic." - K. Auer

User avatar
saguaro
Miko-Class Veteran
Posts: 560
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Organization: Lucky Special Games
itch: saguarofoo
Location: USA
Contact:

Re: Journal System for RenPy Games (& Python in Screen Langu

#26 Post by saguaro »

You would show a specific entry by changing current_journal_page to the appropriate index and then showing the journal screen. You 'unlock' by updating unlocked_journal_pages with the new number of pages that are accessible.

You may be aware, but list indexes start at 0, so current_journal_page = 0 would reference the first entry.

Code: Select all

    $ current_journal_page = 3
    $ unlocked_journal_pages = 4
    show screen notes_screen
Also, if I want the journal entries to remain present when unlocked on the side of the screen in a vertical column over a text box, can I do that? Sort of like the checklist in the nancy drew pc games...
You should! I wasn't able to find an example from that game, but it sounds like the gist of what you want is probably:

Code: Select all

screen vertical_notes:
    vbox:
        for page in range(0, unlocked_journal_pages):
            hbox:
                text journal_entries[page]
We just iterate over the number of unlocked entries and display the text of each.

picobyte
Newbie
Posts: 15
Joined: Mon Mar 14, 2016 2:15 pm
Contact:

Re: Journal System for RenPy Games (& Python in Screen Langu

#27 Post by picobyte »

FWIW: I think you could add some coloring using the pygments library, you'd have to write a parser and lexer to do the coloring for your purpose, though.

Post Reply

Who is online

Users browsing this forum: Stampaw