Ren'Py Button for showing another pic (different pov)

UncleNanard

I am to music what Kanye West is to adult games.
Game Developer
Jul 1, 2017
1,644
1,617
Hi guys,

little question. I want to add a button on my game.
On a scene, you can show another pov with a button.
Someone know how to do that ?

Thank for your help, and for read my horrible English !

exemple : Sans-titre-1.png
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
As with all things RenPy, there are lots of possible solutions.

This is one I just wrote, tested and seems to work how you hope...

Python:
screen four_images():
    default picno = 0
    fixed:
        frame:
            xalign 0.5 yalign 1.0
            background "{}".format("pic" + str(picno))

        label "Scene {}".format(picno + 1):
            xalign 0.15 yalign 0.2

        textbutton "Next >":
            xalign 0.9 yalign 0.2
            action SetScreenVariable("picno", (picno + 1) % 4)

        textbutton "<Exit>":
            xalign 0.9 yalign 0.25
            action Return()



label start:

    scene black with fade

    call screen four_images

    "*** THE END ***"
    return

I'm set , called picno - since this logic only needs to work within the screen.

I use a , with a . The chosen to be used as that background is based on the word "pic" and the value stored in the picno variable. (So pic0, pic1, pic2 and pic3 ... These match 4 images in my /game/images/ folder called pic0.webp, pic1.webp, pic2.webp and pic3.webp.

When you use the "Next>" button, it's action is to increment the picno by 1. But I do a bit of extra math using a rarely used arithmetical operator called modulo / . In this case, I'm using % 4 (modulus 4) to wrap the number back to 0 (zero) when it reaches 4 (four). For more information on modulus/modulo... see . A quick example almost everyone is familiar with is a 24 hour clock... 14 mod 12 (or 14 % 12) = 2. So 14:00 is 2pm. More examples... 15 % 12 = 3. And... 12 % 12 = 0.

I'm even adding the words "Scene 1", "Scene 2", "Scene 3", etc. in the top left corner like your example, based on the current picno value.

This solution is very specific to your problem. Not least, because of the way I've named the images 0, 1, 2, 3.

But you could have done something else, like have 4 separate - then have the action of the button be to jump to a that showed the next screen. Each screen having a separate image, but identical buttons.
 

UncleNanard

I am to music what Kanye West is to adult games.
Game Developer
Jul 1, 2017
1,644
1,617
Thanks you very much, this is exactly what i need.
I m very impressed because with my level those variable are impossible.

But i think with your explications i have understand everything you wrote and i will try to add a previous button, i think i can.

Thank you so much.

Edit : omg i did it, i have add a previous button :p

Thanks x10000
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,963
16,197
As with all things RenPy, there are lots of possible solutions.
Another one that perhaps match more what he had in mind:
Python:
init python:

    #  Interface turning the feature On/Off
    def multiPov( state ):
        #  Show the screen if it isn't already the case
        if renpy.has_screen( "multiPov" ) is None:
            renpy.show_screen( "multiPov" )
        # Change the state
        store.multiPovFlag = state
        # Reset the view
        store.PoV = "view0"

# Screen offering the selection
screen multiPov():
    # Will only be visible if "multiPov" is True
    showif multiPovFlag:
        vbox:
            textbutton "view 1":
                action SetVariable( PoV, "view1" )
            textbutton "view 2":
                action SetVariable( PoV, "view2" )
            textbutton "view 3":
                action SetVariable( PoV, "view3" )

# Flag telling if the screen have to be seen or not
default multiPovFlag = False
# Define the image shown
default PoV = "view0"

label whatever:
    # Turn the multiPov feature On
    $ multiPov( True )
    #  Ren'Py will display the image located on "images/myMultiView/"
    # and named "scene1_" + the content of /PoV/
    scene expression "images/myMultiView/scene1_[PoV].jpg"
    "blablabla"
    "bliblibli"
    # Then turn it Off
    $ multiPov( False )
For this to works, you need to have four images "images/myMultiView/scene1_view0.jpg", "images/myMultiView/scene1_view1.jpg", "images/myMultiView/scene1_view2.jpg" and "images/myMultiView/scene1_view3.jpg".

The whole thing rely on Ren'Py dynamism. As long as the scene is not replaced, Ren'Py will regularly update it accordingly to the value of PoV. Therefore, change the value of PoV (what the screen do), and the image will change accordingly.

I believe that it's more on the spirit of the intent behind the question, since it don't stop the progress of the game. The player will be able to pass through all the different view without even having to pass the current dialog line. As it can pass multiple dialog line before changing again the point of view.

Edit: Corrected a typo in the script.
 
Last edited:

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
As Anne points out, my solution only shows these images.

I wasn't really thinking about the story continuing while the images (and buttons) are in the background.

You don't have permission to view the spoiler content. Log in or register now.

As always here on F95... Anne will generally have the better technical answer. My answer will "probably" work, but tends to be simpler or be less flexible.

Use whichever answer you can understand the code for. If you understand both... use Anne's. ;) It's always better to not do something than try to copy/paste code you don't understand - since YOU might need to change it again in the future.
 

UncleNanard

I am to music what Kanye West is to adult games.
Game Developer
Jul 1, 2017
1,644
1,617
Another one that perhaps match more what he had in mind:
Python:
init python:

    #  Interface turning the feature On/Off
    def multiPov( state ):
        #  Show the screen if it isn't already the case
        if renpy.has_screen( "multiPov" ) is None:
            renpy.show_screen( "multiPov" )
        # Change the state
        store.multiPov = state
        # Reset the view
        store.PoV = "view0"

# Screen offering the selection
screen multiPov():
    # Will only be visible if "multiPov" is True
    showif multiPov:
        vbox:
            textbutton "view 1":
                action SetVariable( PoV, "view1" )
            textbutton "view 2":
                action SetVariable( PoV, "view2" )
            textbutton "view 3":
                action SetVariable( PoV, "view3" )

# Flag telling if the screen have to be seen or not
default multiPov = False
# Define the image shown
default PoV = "view0"

label whatever:
    # Turn the multiPov feature On
    $ multiPov( True )
    #  Ren'Py will display the image located on "images/myMultiView/"
    # and named "scene1_" + the content of /PoV/
    scene expression "images/myMultiView/scene1_[PoV].jpg"
    "blablabla"
    "bliblibli"
    # Then turn it Off
    $ multiPov( False )
For this to works, you need to have four images "images/myMultiView/scene1_view0.jpg", "images/myMultiView/scene1_view1.jpg", "images/myMultiView/scene1_view2.jpg" and "images/myMultiView/scene1_view3.jpg".

The whole thing rely on Ren'Py dynamism. As long as the scene is not replaced, Ren'Py will regularly update it accordingly to the value of PoV. Therefore, change the value of PoV (what the screen do), and the image will change accordingly.

I believe that it's more on the spirit of the intent behind the question, since it don't stop the progress of the game. The player will be able to pass through all the different view without even having to pass the current dialog line. As it can pass multiple dialog line before changing again the point of view.
Hello, i've tried your, but i have an error :

Code:
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 1933, in script
    $ multiPov(True)
  File "game/script.rpy", line 1933, in <module>
    $ multiPov(True)
TypeError: 'bool' object is not callable

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

Full traceback:
  File "game/script.rpy", line 1933, in script
    $ multiPov(True)
  File "renpy/ast.py", line 928, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "renpy/python.py", line 2245, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "game/script.rpy", line 1933, in <module>
    $ multiPov(True)
TypeError: 'bool' object is not callable
 

UncleNanard

I am to music what Kanye West is to adult games.
Game Developer
Jul 1, 2017
1,644
1,617
As Anne points out, my solution only shows these images.

I wasn't really thinking about the story continuing while the images (and buttons) are in the background.

You don't have permission to view the spoiler content. Log in or register now.

As always here on F95... Anne will generally have the better technical answer. My answer will "probably" work, but tends to be simpler or be less flexible.

Use whichever answer where you can understand the code for. If you understand both... use Anne's. ;) It's always better to not do something than try to copy/paste code you don't understand - since YOU might need to change it again in the future.
Thank for the adding.
I will try it.
But if i don't have text it's not really a problem because this is just to have a second pov of the scene.

edit : I will probably use the 2 variables. Sometimes for pov only, sometimes for pov + story.

Thank you very much.

The next step for me is to use imagebutton instead of textbutton, i think i can do it alone.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,963
16,197
Hello, i've tried your, but i have an error :
Oops, my bad. I wrote it on the fly, between two beers, while looking at the AFC finals, and it wasn't such a great idea ; I use the same name for the function and the flag, what obviously wouldn't works.

I edited my message, the code should now works.


As always here on F95... Anne will generally have the better technical answer. My answer will "probably" work, but tends to be simpler or be less flexible.
Not always, and not necessarily better technically. I think the main difference is my weirdness ; especially when I past the week writing test suits. After hours having to be rigorous at works, thinking outside of the box keep the passion living. Therefore, your answer tend to be more academical, and mine sometimes totally crazy.
But there's rarely one that is better than the other. And it's what I like with Ren'Py, this multiple way to solve a problem, because it generally mean that among the answer gave, there will always be one understood by the person who need it.


If you understand both... use Anne's. ;)
Well, now that I edited the typo, yeah, why not :whistle: