Hide/switch lists of items in journal on button click

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
wtxart
Newbie
Posts: 4
Joined: Sun Feb 05, 2017 10:41 am
Contact:

Hide/switch lists of items in journal on button click

#1 Post by wtxart »

I'm trying to create a journal for a mystery game that records the main character's observations through the course of the story. Other games describe the same functionality as a codex or glossary.

My goal: a screen, accessible from navigation, which displays categories as textbuttons, such as People and Objects. When Objects is clicked, the screen displays a list of objects. When People is clicked, the objects list disappears and is replaced by a people list. The category buttons remain visible.

What I have: a screen, accessible from navigation, which displays categories. The buttons are set to Return as a placeholder.

My question: I don't know if I should be making the lists with multiple screens, vboxes inside a screen, etc., and since I'm not an experienced coder, there's a good chance I'm missing something obvious. How do I make lists that I can conditionally show and hide on button click?

Code: Select all

label journal_start:

screen journal():

    tag menu

    use game_menu(_("Journal"), scroll="viewport"):
        
        frame:
            vbox:
                style_prefix "radio"
                label _("Categories")
                textbutton _("People"):
                    action Return(True)
                textbutton _("Objects"):
                    action Return(True)

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Hide/switch lists of items in journal on button click

#2 Post by Per K Grok »

wtxart wrote: Wed Jul 11, 2018 3:43 pm I'm trying to create a journal for a mystery game that records the main character's observations through the course of the story.
-----
How do I make lists that I can conditionally show and hide on button click?
------
There are more questions in that than is easy to handle in one post, however, here is an example on one way you could show different lists by pushing a button. I'm trying to keep it very simple so it should be easier to understand.
When you get the principals you can use that to make something different looking.

Code for script

Code: Select all

image bg purpleBG= "#f0f"

default listC=0

label start:

    $ l1_list=["stuff 1", "stuff 2", "stuff 3"]
    $ l2_list=["other Stuff 1", "other Stuff 2","other Stuff 3","other Stuff 4"]
    $ l3_list=["item 1", "item 2"]

    jump notebook

label listcounter:
    $ listC += 1
    if listC>2:
        $ listC=0
    jump notebook

label notebook:
    show bg purpleBG
    show screen notes

    $ renpy.pause (hard=True)

label someThingElse:
    hide screen notes
    "the End"
    return
    
code for screen

Code: Select all

screen notes:
    textbutton "lists" action Jump ("listcounter") xpos 10  ypos 60
    textbutton "exit" action Jump ("someThingElse") xpos 10 ypos 80


    if listC==0:
        text l1_list[0]:
            xpos 80
            ypos 60
        text l1_list[1]:
            xpos 80
            ypos 80
        text l1_list[2]:
            xpos 80
            ypos 100

    elif listC==1:
        text l2_list[0]:
            xpos 80
            ypos 60
       text l2_list[1]:
            xpos 80
            ypos 80
        text l2_list[2]:
            xpos 80
            ypos 100
        text l2_list[3]:
            xpos 80
            ypos 120

    elif listC==2:
        text l3_list[0]:
            xpos 80
            ypos 60
        text l3_list[1]:
            xpos 80
            ypos 80
The way the lists are written out in the code above is not a very effective way. I did that to make it more clear what is happening. A better way to do it is this.

Code: Select all


     $ yp = 60

     if listC==0:
        for item in l1_list:
            text item:
                xpos 80
                ypos yp
            $ yp += 20

    elif listC==1:
        for item in l2_list:
            text item:
                xpos 80
                ypos yp
            $ yp += 20
            
    elif listC==2:
        for item in l3_list:
            text item:
                xpos 80
                ypos yp
            $ yp += 20

It does the same thing but will work even if the length of the list is changed by adding or removing items.

I hope this is of some help.

wtxart
Newbie
Posts: 4
Joined: Sun Feb 05, 2017 10:41 am
Contact:

Re: Hide/switch lists of items in journal on button click

#3 Post by wtxart »

Thank you for responding. I tested your code, and it does work, but I believe I've miscommunicated what I was going for. I want to elaborate on the code I've already written, but I don't know how. Sorry for the confusion.
Just now, I tried showing a screen, which I thought might work because I know you can toggle a screen's visibility, but it crashed.

My code:

Code: Select all

label journal_start:

screen journal():

    tag menu

    use game_menu(_("Journal"), scroll="viewport"):
        
        frame:
            vbox:
                label _("Categories")
                textbutton _("People"):
                    action Show(j_people)
                textbutton _("Objects"):
                    action Return(True)

screen j_people():
    
    vbox:
        text "Test."
The error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "game/journal.rpy", line 5, in execute
    screen journal():
  File "game/journal.rpy", line 5, in execute
    screen journal():
  File "game/journal.rpy", line 9, in execute
    use game_menu(_("Journal"), scroll="viewport"):
  File "game/screens.rpy", line 420, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 420, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 429, in execute
    frame:
  File "game/screens.rpy", line 432, in execute
    hbox:
  File "game/screens.rpy", line 438, in execute
    frame:
  File "game/screens.rpy", line 441, in execute
    if scroll == "viewport":
  File "game/screens.rpy", line 443, in execute
    viewport:
  File "game/screens.rpy", line 452, in execute
    vbox:
  File "game/screens.rpy", line 453, in execute
    transclude
  File "game/journal.rpy", line 9, in execute
    use game_menu(_("Journal"), scroll="viewport"):
  File "game/journal.rpy", line 11, in execute
    frame:
  File "game/journal.rpy", line 12, in execute
    vbox:
  File "game/journal.rpy", line 14, in execute
    textbutton _("People"):
  File "game/journal.rpy", line 14, in keywords
    textbutton _("People"):
NameError: name 'j_people' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "D:\renpy-6.99.12.4-sdk\renpy\ast.py", line 862, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "D:\renpy-6.99.12.4-sdk\renpy\python.py", line 1912, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "D:\renpy-6.99.12.4-sdk\renpy\ui.py", line 287, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "D:\renpy-6.99.12.4-sdk\renpy\display\core.py", line 2649, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "D:\renpy-6.99.12.4-sdk\renpy\display\core.py", line 3033, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "D:\renpy-6.99.12.4-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "D:\renpy-6.99.12.4-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "D:\renpy-6.99.12.4-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "D:\renpy-6.99.12.4-sdk\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "D:\renpy-6.99.12.4-sdk\renpy\display\screen.py", line 424, in visit_all
    callback(self)
  File "D:\renpy-6.99.12.4-sdk\renpy\display\core.py", line 3033, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "D:\renpy-6.99.12.4-sdk\renpy\display\screen.py", line 434, in per_interact
    self.update()
  File "D:\renpy-6.99.12.4-sdk\renpy\display\screen.py", line 619, in update
    self.screen.function(**self.scope)
  File "game/journal.rpy", line 5, in execute
    screen journal():
  File "game/journal.rpy", line 5, in execute
    screen journal():
  File "game/journal.rpy", line 9, in execute
    use game_menu(_("Journal"), scroll="viewport"):
  File "game/screens.rpy", line 420, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 420, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 429, in execute
    frame:
  File "game/screens.rpy", line 432, in execute
    hbox:
  File "game/screens.rpy", line 438, in execute
    frame:
  File "game/screens.rpy", line 441, in execute
    if scroll == "viewport":
  File "game/screens.rpy", line 443, in execute
    viewport:
  File "game/screens.rpy", line 452, in execute
    vbox:
  File "game/screens.rpy", line 453, in execute
    transclude
  File "game/journal.rpy", line 9, in execute
    use game_menu(_("Journal"), scroll="viewport"):
  File "game/journal.rpy", line 11, in execute
    frame:
  File "game/journal.rpy", line 12, in execute
    vbox:
  File "game/journal.rpy", line 14, in execute
    textbutton _("People"):
  File "game/journal.rpy", line 14, in keywords
    textbutton _("People"):
  File "<screen language>", line 15, in <module>
NameError: name 'j_people' is not defined

Windows-8-6.2.9200
Ren'Py 7.0.0.196
Mystery Game 1.0
Sun Jul 15 21:32:29 2018

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Hide/switch lists of items in journal on button click

#4 Post by Per K Grok »

wtxart wrote: Sun Jul 15, 2018 10:43 pm Thank you for responding. I tested your code, and it does work, but I believe I've miscommunicated what I was going for. I want to elaborate on the code I've already written, but I don't know how. Sorry for the confusion.

Just now, I tried showing a screen, which I thought might work because I know you can toggle a screen's visibility, but it crashed.

------
action Show(j_people)
-----

Should be
action Show("j_people")

wtxart
Newbie
Posts: 4
Joined: Sun Feb 05, 2017 10:41 am
Contact:

Re: Hide/switch lists of items in journal on button click

#5 Post by wtxart »

That solved it. Thanks for helping me out!

Post Reply

Who is online

Users browsing this forum: No registered users