Ren'Py Photo Book

iOtero

Active Member
Aug 4, 2020
925
1,459
Hi, I have a problem with creating a photo book.
I want it to make a grid of smaller images and when I click on that image it opens the image to its actual size.

I have coded this:

Code:
        grid gui.file_slot_cols gui.file_slot_rows: #grid 3 3 --> 9x9
            style_prefix "slot"

            xalign 0.5
            yalign 0.5
            xoffset 160
            spacing gui.slot_spacing

            imagebutton: idle Transform("images/album/raquel/raquel31.webp", zoom=0.2) action Show("images/album/raquel/raquel31.webp")
            imagebutton: idle Transform("images/album/raquel/raquel32.webp", zoom=0.2) action Show("images/album/raquel/raquel32.webp")
            imagebutton: idle Transform("images/album/raquel/raquel33.webp", zoom=0.2) action Show("images/album/raquel/raquel33.webp")
            imagebutton: idle Transform("images/album/raquel/raquel34.webp", zoom=0.2) action Show("images/album/raquel/raquel34.webp")
            imagebutton: idle Transform("images/album/raquel/raquel35.webp", zoom=0.2) action Show("images/album/raquel/raquel35.webp")
            imagebutton: idle Transform("images/album/raquel/raquel36.webp", zoom=0.2) action Show("images/album/raquel/raquel36.webp")
            imagebutton: idle Transform("images/album/raquel/raquel37.webp", zoom=0.2) action Show("images/album/raquel/raquel37.webp")
            imagebutton: idle Transform("images/album/raquel/raquel38.webp", zoom=0.2) action Show("images/album/raquel/raquel38.webp")
And it presents me the grid on screen with the reduced images without any problem.
The problem appears when it tries to execute the "action" instruction.
What I don't know is what I'm doing wrong.

I get this error:

Code:
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 "renpy/common/00action_control.rpy", line 126, in __call__
    renpy.show_screen(self.screen, *self.args, **self.kwargs)
Exception: Screen images/album/raquel/raquel11.webp is not known.


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

Full traceback:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "renpy/ast.py", line 913, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "renpy/python.py", line 2111, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy/display/core.py", line 2978, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "renpy/display/core.py", line 3776, in interact_core
    rv = root_widget.event(ev, x, y, 0)
  File "renpy/display/layout.py", line 1027, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "renpy/display/transition.py", line 48, in event
    return self.new_widget.event(ev, x, y, st) # E1101
  File "renpy/display/layout.py", line 1027, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "renpy/display/layout.py", line 1027, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "renpy/display/screen.py", line 720, in event
    rv = self.child.event(ev, x, y, st)
  File "renpy/display/layout.py", line 1027, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "renpy/display/layout.py", line 245, in event
    rv = d.event(ev, x - xo, y - yo, st)
  File "renpy/display/behavior.py", line 969, in event
    return handle_click(self.clicked)
  File "renpy/display/behavior.py", line 904, in handle_click
    rv = run(action)
  File "renpy/display/behavior.py", line 323, in run
    return action(*args, **kwargs)
  File "renpy/common/00action_control.rpy", line 126, in __call__
    renpy.show_screen(self.screen, *self.args, **self.kwargs)
  File "renpy/display/screen.py", line 1115, in show_screen
    raise Exception("Screen %s is not known.\n" % (name[0],))
Exception: Screen images/album/raquel/raquel11.webp is not known.
[code]

Thanks for your help.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
You're mistaking what action Show() is for. It's actually to , not an image.

The clue is the exception...
Exception: Screen images/album/raquel/raquel11.webp is not known.

Looking at , I can't actually see an equivalent of scene or show. I can think of a couple of workarounds, but they would be kludges... so I'll hold off saying what, in the hope that someone comes up with a "real" solution.
 
  • Like
Reactions: iOtero

iOtero

Active Member
Aug 4, 2020
925
1,459
You're mistaking what action Show() is for. It's actually to , not an image.

The clue is the exception...
Exception: Screen images/album/raquel/raquel11.webp is not known.

Looking at , I can't actually see an equivalent of scene or show. I can think of a couple of workarounds, but they would be kludges... so I'll hold off saying what, in the hope that someone comes up with a "real" solution.
Thank you, I thought it was too easy what I was trying to do. (y) :p
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,359
15,270
I can think of a couple of workarounds, but they would be kludges... so I'll hold off saying what, in the hope that someone comes up with a "real" solution.
The simplest is probably to have a screen that will just contain the image ; with the name of the said image past as parameter to the screen.
Normally this should works :

Code:
    [...]
    imagebutton:
        idle Transform("images/album/raquel/raquel31.webp", zoom=0.2)
        action Show( "bookImg", "images/album/raquel/raquel31.webp" )
    [...]

screen bookImg( img ):
    vbox:
        xalign 0.5
        yalign 0.5

        add img
The use of a vbox is perhaps not needed, but add has one of the smallest set of properties, so I'm not sure that you can effectively align it directly.

Edit:Hmm, obviously it still miss things like a "close" button. But well, it's the principle and today I can't really do better, sorry.
 

iOtero

Active Member
Aug 4, 2020
925
1,459
The simplest is probably to have a screen that will just contain the image ; with the name of the said image past as parameter to the screen.
Normally this should works :

Code:
    [...]
    imagebutton:
        idle Transform("images/album/raquel/raquel31.webp", zoom=0.2)
        action Show( "bookImg", "images/album/raquel/raquel31.webp" )
    [...]

screen bookImg( img ):
    vbox:
        xalign 0.5
        yalign 0.5

        add img
The use of a vbox is perhaps not needed, but add has one of the smallest set of properties, so I'm not sure that you can effectively align it directly.

Edit:Hmm, obviously it still miss things like a "close" button. But well, it's the principle and today I can't really do better, sorry.
It is a very good idea, but yes, the case is that we will have to close the image.... Thank you very much, I hope you will solve everything for me. My apologies for being a poor developer... :LOL:
Edit: Of course I'll keep working on it too... :unsure:
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,359
15,270
It is a very good idea, but yes, the case is that we will have to close the image....
Code:
screen bookImg( img ):

     modal True

    vbox:
        xalign 0.5
        yalign 0.5

        add img

    textbutton "close":
        xalign 1.0
        yalign 0.0
        action Hide( "bookImg" )
It need some styling, but like I don't know what you User Interface look like, it's something that I can't do.
 
  • Like
Reactions: iOtero

iOtero

Active Member
Aug 4, 2020
925
1,459
Code:
screen bookImg( img ):

     modal True

    vbox:
        xalign 0.5
        yalign 0.5
        add img
It need some styling, but like I don't know what you User Interface look like, it's something that I can't do.
Thank you, I have done this:

Code:
screen raquel11(img):
    vbox:
        xalign 0.5
        yalign 0.5
        add img
    textbutton _("Cerrar"):
        style "return_button"
        action Hide("raquel11")

imagebutton idle Transform("images/album/raquel/raquel11.webp", zoom=0.2) action Show("raquel11", "images/album/raquel/raquel11.webp")
And it shows me this error:

Code:
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()
TypeError: 'unicode' object is not callable

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

Full traceback:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "renpy/ast.py", line 913, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "renpy/python.py", line 2111, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy/display/core.py", line 2978, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "renpy/display/core.py", line 3331, in interact_core
    new_widget=layers_root)
TypeError: 'unicode' object is not callable
EDIT:

Oh, and I have a small problem that I don't know why, the photo album page I access from the main menu as from the quick menu with:

textbutton _("Album de fotos") action ShowMenu("album_fotos")

And depending on a variable that changes the value in the game scripts, the names of the girls appear, but whenever I go to the photo album for the first time it is empty, if I try a second time, it does appear.

Any joke of the renpy bits? :)
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,359
15,270
And it shows me this error:

Code:
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()
TypeError: 'unicode' object is not callable
Sometimes Ren'py is really annoying with its useless traceback :( What is important here, it to know where the error happened in your script, not in the core, but this information is missing.

The only thing this traceback say, is that at one moment, Ren'py is trying to call (execute) a function, and failed because found a string instead. But in the code you shown, really looks correct ; and indeed is correct.
At first, I was tempted to say that it's an unrelated error, but I tried at home (just changing the name of the images), got the same error, and after some try found the real culprit, the Show screen action.
Be noted that there absolutely nothing in the traceback that point it as being the source of the error ; Ren'py error can sometimes be the useless thing in the world.


So, I took a look closer at the documentation, this time having in mind that there's something wrong, and it was now obvious ; even more obvious when I verified by taking a look at the source :
Show(screen, transition=None, *args, **kwargs)
It say that there's one mandatory argument (screen), followed by one optional argument (transition), and that following this, any argument ("value") or keyword argument ("name=value"), are anonymous.
Technically it's correct, and I never thought about it more than that, not having need to use the screen action that way. But the code is wrote that way :
Code:
        def __init__(self, screen, transition=None, *args, **kwargs):
            self.screen = screen
            self.transition = transition
            self.args = args
            self.kwargs = kwargs
What imply that the transition parameter is optional only if you just provide the screen name, or use keyword arguments. But if you use regular argument, then it become mandatory ; the second argument will be always assigned to transition.

So, to solve your problem, you need to have this as action : Show("raquel11", None, "images/album/raquel/raquel11.webp")
It will give a value to the now not at all optional transition argument, and then works correctly.


And depending on a variable that changes the value in the game scripts, the names of the girls appear, but whenever I go to the photo album for the first time it is empty, if I try a second time, it does appear.
My guess is that the variable have no value prior to the first time the screen is shown. Try to give it a value by default, and it should solve the problem.
 
  • Like
Reactions: iOtero

iOtero

Active Member
Aug 4, 2020
925
1,459
Finally, I have used this and have had no problems.

Code:
screen raquel11():
    add "images/album/raquel/raquel11.webp"
    textbutton _("Volver") style "return_button" action Hide("raquel11")
In scripts.rpy I have the variable defined like this:

Code:
define raquel_01_fotos = False
So it must be something else. I can only think of updating the main menu somehow.

Thank you very much for your help, as always, you have been very helpful.
 
Last edited: