Button which opens up a menu screen

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
Kinmoku
Miko-Class Veteran
Posts: 509
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: Love IRL, Memories
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Button which opens up a menu screen

#1 Post by Kinmoku » Mon May 18, 2020 11:12 am

Hi all,

I'm trying to create a button which opens up a choice menu screen (It's to comment on a picture in a social media-like interface).

I've been reading this post: viewtopic.php?t=44767 , though I am unsure how to proceed.

The screen which has the button is below:

Code: Select all

screen pic_violet(log):
    zorder 0
    modal True 
    tag sharkmenu
    use shark_interface
    
    add "images/menu_on.png" xpos 0 ypos 344
    
    imagebutton idle "images/back_button.png" clicked [Hide("pic_violet"), Show("feudal_fantasy_community")] xpos 16 ypos 960 focus_mask True
    
    imagebutton idle "images/post_button.png" action [Show("write_post"), choice_items1]  xpos 1700 ypos 16 focus_mask True
    
    text _("Feudal Fantasy Community") color "#000000" xpos 30 ypos 16
    
    vbox:
        xpos 334
        ypos 144
        spacing 20
        add "violet"
    
    frame:
        background None
        use chat_log2(log)
        
        
screen write_post: ## the custom choice screen I want to use here
    add "images/write_post.png" xpos 454 ypos 190
    
    text _("Write Post") color "#000000" xpos 890 ypos 202
    
    vbox:
        xpos 660
        ypos 350
        
        label "Select:"

        vbox:
            #for i in items:
            textbutton i.caption action i.action style "black_text" ## I'm unsure what to put here.
        
    hbox:
        xpos 662
        ypos 732
        
        spacing 40
        
        button:
            action Hide("write_post")
            xysize (290, 98)
            background "confirm_button"
            text _("Cancel") style "black_text" xpos 78 ypos 20
        
        
My script shows up as follows:

Code: Select all

label pic_violet:
    
    show screen pic_violet(vhslog)
    
    $ vhslog.add_chat(msg="Wow :O", nick="Wolfie", avatar="images/avatars/wolfie.png", posttime="1 day ago") ## previous comments you can read
    $ vhslog.add_chat(msg="OMG you can draw so much better than me XD", nick="Markus", avatar="images/avatars/markus.png", posttime="1 day ago")
    $ vhslog.add_chat(msg="Haha ;-)", nick="Lindsay222", avatar="images/avatars/lindsay.png", posttime="1 day ago")
    
    $ choice_items1 = ["Wow!", "I love it!", "Meh"] # I want these choice to show when/if the player clicks the post button
    
    pause
How do I get this to work?

User avatar
hell_oh_world
Veteran
Posts: 352
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Location: Philippines
Contact:

Re: Button which opens up a menu screen

#2 Post by hell_oh_world » Mon May 18, 2020 11:50 pm

maybe use the screen write_post directly instead of setting the post messages via variable...

Code: Select all

screen write_post(items): ## the custom choice screen I want to use here
    add "images/write_post.png" xpos 454 ypos 190
    
    text _("Write Post") color "#000000" xpos 890 ypos 202

    default picked = None
    
    if not picked:
        vbox:
            xpos 660
            ypos 350
        
            label "Select:"

            vbox:
                for i in items:
                    textbutton i:
                        action SetScreenVariable("picked", i)
                        style "black_text"

    else picked:
        hbox:
            xpos 662
            ypos 732
        
            spacing 40
        
            vbox:
                text _("Send '[picked]' as the post message?")
                hbox:
                    textbutton "Yes" action [Function(vhslog.add_chat, msg=picked, nick="Markus", avatar="images/avatars/markus.png", posttime="Just now"), Hide("write_post")]
                    textbutton "No" action SetScreenVariable("picked", None)

label pic_violet:
    
    show screen pic_violet(vhslog)
    
    $ vhslog.add_chat(msg="Wow :O", nick="Wolfie", avatar="images/avatars/wolfie.png", posttime="1 day ago") ## previous comments you can read
    $ vhslog.add_chat(msg="OMG you can draw so much better than me XD", nick="Markus", avatar="images/avatars/markus.png", posttime="1 day ago")
    $ vhslog.add_chat(msg="Haha ;-)", nick="Lindsay222", avatar="images/avatars/lindsay.png", posttime="1 day ago")
    
    show screen write_post(["Wow!", "I love it!", "Meh"])
    
    pause

User avatar
Kinmoku
Miko-Class Veteran
Posts: 509
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: Love IRL, Memories
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Button which opens up a menu screen

#3 Post by Kinmoku » Tue May 19, 2020 4:02 am

hell_oh_world wrote:
Mon May 18, 2020 11:50 pm
maybe use the screen write_post directly instead of setting the post messages via variable...

Code: Select all

screen write_post(items): ## the custom choice screen I want to use here
    add "images/write_post.png" xpos 454 ypos 190
    
    text _("Write Post") color "#000000" xpos 890 ypos 202

    default picked = None
    
    if not picked:
        vbox:
            xpos 660
            ypos 350
        
            label "Select:"

            vbox:
                for i in items:
                    textbutton i:
                        action SetScreenVariable("picked", i)
                        style "black_text"

    else picked:
        hbox:
            xpos 662
            ypos 732
        
            spacing 40
        
            vbox:
                text _("Send '[picked]' as the post message?")
                hbox:
                    textbutton "Yes" action [Function(vhslog.add_chat, msg=picked, nick="Markus", avatar="images/avatars/markus.png", posttime="Just now"), Hide("write_post")]
                    textbutton "No" action SetScreenVariable("picked", None)

label pic_violet:
    
    show screen pic_violet(vhslog)
    
    $ vhslog.add_chat(msg="Wow :O", nick="Wolfie", avatar="images/avatars/wolfie.png", posttime="1 day ago") ## previous comments you can read
    $ vhslog.add_chat(msg="OMG you can draw so much better than me XD", nick="Markus", avatar="images/avatars/markus.png", posttime="1 day ago")
    $ vhslog.add_chat(msg="Haha ;-)", nick="Lindsay222", avatar="images/avatars/lindsay.png", posttime="1 day ago")
    
    show screen write_post(["Wow!", "I love it!", "Meh"])
    
    pause
Thank you, though I really need a button instead of "show screen write_post(["Wow!", "I love it!", "Meh"])" coming up automatically.

I thought maybe I could jump to a label with this code using the button, but even when I set it all up, the choices/ items are not there :(

Here's my code. I made a few changes:

Code: Select all

screen write_post(items):
    add "images/write_post.png" xpos 454 ypos 190
    
    text _("Write Post") color "#000000" xpos 890 ypos 202
    
    default picked = None
    
    if not picked:
        vbox:
            xpos 660
            ypos 350
        
            label "Select:"

            vbox:
                for i in items:
                    textbutton i:
                        action SetScreenVariable("picked", i)
                        style "red_text" ## changed this to ensure I can see it on the background
                        
    else:# picked: didn't work
        hbox:
            xpos 662
            ypos 732
        
            spacing 40
        
            vbox:
                text _("Send '[picked]' as the post message?")
                hbox:
                    textbutton "Yes" action [Function(vhslog.add_chat, msg=picked, nick="Markus", avatar="images/avatars/markus.png", posttime="Just now"), Hide("write_post")] style "red_text"
                    textbutton "No" action SetScreenVariable("picked", None) style "red_text"
                    
                    
                    
screen pic_violet(log):
    zorder 0
    modal True 
    tag sharkmenu
    use shark_interface
    
    add "images/menu_on.png" xpos 0 ypos 344
    
    imagebutton idle "images/back_button.png" clicked [Hide("pic_violet"), Show("feudal_fantasy_community")] xpos 16 ypos 960 focus_mask True
    
    imagebutton idle "images/post_button.png" action Jump("vhs_post") xpos 1700 ypos 16 focus_mask True
    text _("Post") color "#000000" xpos 1780 ypos 30
    
    text _("Feudal Fantasy Community") color "#000000" xpos 30 ypos 16
    
    vbox:
        xpos 334
        ypos 144
        spacing 20
        add "violet"
        text "377 people liked this."
    
    frame:
        background None
        use chat_log2(log)
In script:

Code: Select all

    
label pic_violet_hanzo_sword:
    
    show screen pic_violet_hanzo_sword(vhslog)
    
    $ vhslog.add_chat(msg="Wow :O", nick="Wolfie", avatar="images/avatars/wolfie.png", posttime="1 day ago")
    $ vhslog.add_chat(msg="OMG you can draw so much better than me XD", nick="Markus", avatar="images/avatars/markus.png", posttime="1 day ago")
    $ vhslog.add_chat(msg="Haha ;-)", nick="Lindsay222", avatar="images/avatars/lindsay.png", posttime="1 day ago")

    pause
    
    
label vhs_post:
    show screen write_post(["Wow!", "I love it!", "Meh"])
        
    pause

Post Reply

Who is online

Users browsing this forum: renardjap