How to put a button on top of an image

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
YourLocalAlchemist
Newbie
Posts: 13
Joined: Sun Jan 17, 2016 7:46 pm
Contact:

How to put a button on top of an image

#1 Post by YourLocalAlchemist »

I thought I figured out everything I needed, but I guess not... I have an image that pops up when I press one button (it's for an in-game journal), and the other button isn't showing up like it's supposed to. Is there something I need to add to this?

Code: Select all

style usual_style:
    xalign 0
    yalign 0
    spacing 5

screen hbox_add_notebook(buttons):
    hbox:
        add "notebook.jpg":
            xalign 0
            yalign 0
        for button in options:
            textbutton button:
                action Hide("hbox_add_notebook")
                activate_sound "page_flip.wav"
   
screen hbox_screen_1(buttons):
    hbox:
        style "usual_style"
        xmaximum 30
        box_wrap True
        for button in buttons:
            textbutton button:
                action Show("hbox_add_notebook", buttons=options)
                activate_sound "page_flip.wav"
(In case you couldn't tell, it's the "hbox_add_notebook" one that I can't see.)

guiltyGG
Newbie
Posts: 13
Joined: Sat Aug 19, 2017 8:51 am
Contact:

Re: How to put a button on top of an image

#2 Post by guiltyGG »

YourLocalAlchemist wrote: Sun Mar 25, 2018 7:41 pm I thought I figured out everything I needed, but I guess not... I have an image that pops up when I press one button (it's for an in-game journal), and the other button isn't showing up like it's supposed to. Is there something I need to add to this?

Code: Select all

style usual_style:
    xalign 0
    yalign 0
    spacing 5

screen hbox_add_notebook(buttons):
    hbox:
        add "notebook.jpg":
            xalign 0
            yalign 0
        for button in options:
            textbutton button:
                action Hide("hbox_add_notebook")
                activate_sound "page_flip.wav"
   
screen hbox_screen_1(buttons):
    hbox:
        style "usual_style"
        xmaximum 30
        box_wrap True
        for button in buttons:
            textbutton button:
                action Show("hbox_add_notebook", buttons=options)
                activate_sound "page_flip.wav"
(In case you couldn't tell, it's the "hbox_add_notebook" one that I can't see.)
I think your 'action' statements might be off, as well as the function calls of 'activate_sound':

Code: Select all

style usual_style:
    xalign 0.0 ##
    yalign 0.0 ##
    spacing 5

screen hbox_add_notebook(buttons):
    hbox:
        add "notebook.jpg":
            xalign 0.0 ##
            yalign 0.0 ##
        for button in options:
            textbutton button:
                action [Hide("hbox_add_notebook"), activate_sound("page_flip.wav")] ##
   
screen hbox_screen_1(buttons):
    hbox:
        style "usual_style"
        xmaximum 30
        box_wrap True
        for button in buttons:
            textbutton button:
                action [Show("hbox_add_notebook", buttons=options), activate_sound("page_flip.wav")] ##
This works:

Code: Select all

image bg = Solid('#000')

init python:
    aaa = 30

screen test():
    textbutton "Click Me":
        xalign 0.5 yalign 0.5
        action [SetVariable("aaa", 25), Return()]
            
label start:
    scene bg
    "val = [aaa]"
    call screen test()
    "val = [aaa]"    

    return
Are you getting error messages from Ren'Py?

DannX
Regular
Posts: 99
Joined: Mon Mar 12, 2018 11:15 am
Contact:

Re: How to put a button on top of an image

#3 Post by DannX »

activate_sound is a button property, although it does call a function, it's not a function itself. TC used it correctly.

The problem seems to be that arguments in both screens are mixed up. In the first screen you are making the list from an unexisting options variable, that I suppose is the argument you currently have as buttons. And in the second screen, you'll probably want to change the Show() action too so they match up. So:

Code: Select all

screen hbox_add_notebook(options):
    hbox:
        add "notebook.jpg":
            xalign 0
            yalign 0
        for button in options:
            textbutton button:
                activate_sound "page_flip.wav"
                action Hide("hbox_add_notebook")

   
screen hbox_screen_1(buttons):
    hbox:
        style "usual_style"
        xmaximum 30
        box_wrap True
        for button in buttons:
            textbutton button:
                activate_sound "page_flip.wav"
                action Show("hbox_add_notebook", options=buttons)


YourLocalAlchemist
Newbie
Posts: 13
Joined: Sun Jan 17, 2016 7:46 pm
Contact:

Re: How to put a button on top of an image

#4 Post by YourLocalAlchemist »

No, I am not getting errors. I just need the back button to show up over the notebook image.

Post Reply

Who is online

Users browsing this forum: Ocelot