[Solved] Help with CG gallery!

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
Black Cat 2412
Regular
Posts: 74
Joined: Wed Aug 16, 2017 10:10 am
Projects: Rapunzel: A classic retold
Deviantart: BlackCat2412
Location: Vietnam
Contact:

[Solved] Help with CG gallery!

#1 Post by Black Cat 2412 »

Good day

Being the noob that I am, I still very, very much want to have a CG gallery in my game. So I follow the doc's instruction: https://www.renpy.org/doc/html/rooms.html#image-gallery and come up with this code:

Code: Select all

### Define the image ###
image CG1 = "CG/CG1.jpg"
image CG2_1 = "CG/CG2_1.jpg"
image CG2_2 = "CG/CG2_2.jpg"

### Create the gallery object ###
init python:
    # Create the gallery object.
    g = Gallery()

    #Add buttons and images to the gallery. 

     # A button that contains an image.
    g.button("Gallery_b_1")
    g.unlock_image("CG1")
    

    # This button has two images associated with it. 
    g.button("Gallery_b_2")
    g.unlock_image("CG2_1")
    g.unlock_image("CG2_2")
    
    # The transition used when switching images.
    g.transition = dissolve
    
### The gallery screen ###
screen gallery():
    # Ensure this replaces the main menu.
    tag menu

    # The background.
    add "gui/game_menu.png"

    # A grid of buttons.
    vbox:
    #grid 1 2:

        xfill True
        yfill True

        # Call make_button to show a particular button.
        add g.make_button("Gallery_b_1", "CG/CGlock.jpg", xalign=0.5, yalign=0.5 )
        add g.make_button("Gallery_b_2", "CG/CGlock.jpg", xalign=0.5, yalign=0.5 )
     

        # The screen is responsible for returning to the main menu. It could also
        # navigate to other gallery screens.
        textbutton "Return" action Return() xalign 0.5 yalign 0.5

        
### Making the gallery accessible through an Extra screen ###
screen extra():

    tag menu
    use game_menu(_("Extra")):

        style_prefix "extra"

        vbox:
            textbutton _("{size=50}Image Gallery{/size}") action ShowMenu("gallery") xpos 240 ypos 150
            
style extra_label is gui_label
style extra_label_text is gui_label_text
style extra_text is gui_text

style extra_label_text:
    size gui.label_text_size
For visualization: here is the image folder for the gallery:
Image

Let's get to the problem:
  • With the code above, going into the gallery result in...:

    Code: Select all

    I'm sorry, but an uncaught exception occurred.
    
    While running game code:
    Exception: Grid overfull.
    
    -- Full Traceback ------------------------------------------------------------
    
    Full traceback:
      File "renpy/common/_layout/screen_main_menu.rpym", line 28, in script
        python hide:
      File "D:\CHI\CHI_STUFF\renpy-6.99.12.4-sdk\renpy\ast.py", line 814, in execute
        renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
      File "D:\CHI\CHI_STUFF\renpy-6.99.12.4-sdk\renpy\python.py", line 1719, in py_exec_bytecode
        exec bytecode in globals, locals
      File "renpy/common/_layout/screen_main_menu.rpym", line 30, in <module>
        ui.interact()
      File "D:\CHI\CHI_STUFF\renpy-6.99.12.4-sdk\renpy\ui.py", line 285, in interact
        rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
      File "D:\CHI\CHI_STUFF\renpy-6.99.12.4-sdk\renpy\display\core.py", line 2526, in interact
        repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
      File "D:\CHI\CHI_STUFF\renpy-6.99.12.4-sdk\renpy\display\core.py", line 2883, in interact_core
        self.draw_screen(root_widget, fullscreen_video, (not fullscreen_video) or video_frame_drawn)
      File "D:\CHI\CHI_STUFF\renpy-6.99.12.4-sdk\renpy\display\core.py", line 1955, in draw_screen
        renpy.config.screen_height,
      File "renpy/display/render.pyx", line 427, in renpy.display.render.render_screen (gen\renpy.display.render.c:6806)
        rv = render(root, width, height, 0, 0)
      File "renpy/display/render.pyx", line 196, in renpy.display.render.render (gen\renpy.display.render.c:2978)
        rv = d.render(widtho, heighto, st, at)
      File "D:\CHI\CHI_STUFF\renpy-6.99.12.4-sdk\renpy\display\layout.py", line 693, in render
        surf = render(child, width, height, cst, cat)
      File "renpy/display/render.pyx", line 110, in renpy.display.render.render (gen\renpy.display.render.c:3440)
        cpdef render(d, object widtho, object heighto, double st, double at):
      File "renpy/display/render.pyx", line 196, in renpy.display.render.render (gen\renpy.display.render.c:2978)
        rv = d.render(widtho, heighto, st, at)
      File "D:\CHI\CHI_STUFF\renpy-6.99.12.4-sdk\renpy\display\layout.py", line 693, in render
        surf = render(child, width, height, cst, cat)
      File "renpy/display/render.pyx", line 110, in renpy.display.render.render (gen\renpy.display.render.c:3440)
        cpdef render(d, object widtho, object heighto, double st, double at):
      File "renpy/display/render.pyx", line 196, in renpy.display.render.render (gen\renpy.display.render.c:2978)
        rv = d.render(widtho, heighto, st, at)
      File "D:\CHI\CHI_STUFF\renpy-6.99.12.4-sdk\renpy\display\layout.py", line 693, in render
        surf = render(child, width, height, cst, cat)
      File "renpy/display/render.pyx", line 110, in renpy.display.render.render (gen\renpy.display.render.c:3440)
        cpdef render(d, object widtho, object heighto, double st, double at):
      File "renpy/display/render.pyx", line 196, in renpy.display.render.render (gen\renpy.display.render.c:2978)
        rv = d.render(widtho, heighto, st, at)
      File "D:\CHI\CHI_STUFF\renpy-6.99.12.4-sdk\renpy\display\screen.py", line 623, in render
        child = renpy.display.render.render(self.child, w, h, st, at)
      File "renpy/display/render.pyx", line 110, in renpy.display.render.render (gen\renpy.display.render.c:3440)
        cpdef render(d, object widtho, object heighto, double st, double at):
      File "renpy/display/render.pyx", line 196, in renpy.display.render.render (gen\renpy.display.render.c:2978)
        rv = d.render(widtho, heighto, st, at)
      File "D:\CHI\CHI_STUFF\renpy-6.99.12.4-sdk\renpy\display\layout.py", line 693, in render
        surf = render(child, width, height, cst, cat)
      File "renpy/display/render.pyx", line 110, in renpy.display.render.render (gen\renpy.display.render.c:3440)
        cpdef render(d, object widtho, object heighto, double st, double at):
      File "renpy/display/render.pyx", line 196, in renpy.display.render.render (gen\renpy.display.render.c:2978)
        rv = d.render(widtho, heighto, st, at)
      File "D:\CHI\CHI_STUFF\renpy-6.99.12.4-sdk\renpy\display\layout.py", line 409, in render
        raise Exception("Grid overfull.")
    Exception: Grid overfull.
    
    Windows-7-6.1.7601-SP1
    Ren'Py 6.99.12.4.2187
    Prototype 1.0
    
    \(°ロ\)why??(/ロ°)/how??
  • Try getting rid of the grid and put vbox in instead:

    Code: Select all

    screen gallery():
        # Ensure this replaces the main menu.
        tag menu
    
        # The background.
        add "gui/game_menu.png"
    
        # A grid of buttons.
        vbox:
            xfill True
            yfill True
            # Call make_button to show a particular button.
            add g.make_button("Gallery_b_1", "CG/CGlock.jpg", xalign=0.5, yalign=0.5 )
            add g.make_button("Gallery_b_2", "CG/CGlock.jpg", xalign=0.5, yalign=0.5 )
        
            # The return button
            textbutton "Return" action Return() xalign 0.5 yalign 0.5
    
    result in: Image
    Clicking on the supposed buttons do nothing at all-nothing happens
How can I make this work? I honestly have no idea. Please help me!
Thank you so much in advance

P/S: I would like it this way:
1. As for the three images: One image will take the first button, the second and third will share the same button.
2. In terms of condition: All it required is the image be viewed at least once to be unlocked in the gallery. Plus: when an image is still locked, then its thumbnails in the gallery also show the "locked" image.


Edit: I solved the problem (I feel so silly for asking now), this post can be deleted now, but for those who may have the same problem, here it is:

Code: Select all

screen gallery():
    # Ensure this replaces the main menu.
    tag menu

    # The background.
    add "gui/game_menu.png"

    # Do not use grid- it just did not work (for me at least).
    vbox:

        # Call make_button to show a particular button.
        add g.make_button("Gallery_b_1", locked="CG/CGb_lock.jpg", unlocked= "CG/CGb_1.jpg", xpos = 200, ypos = 200, xsize= 200, ysize = 100) 
        add g.make_button("Gallery_b_2", locked="CG/CGb_lock.jpg", unlocked= "CG/CGb_2.jpg", xpos = 200, ypos = 400, xsize= 200, ysize = 100)
     

        # The screen is responsible for returning to the main menu. It could also
        # navigate to other gallery screens.
        textbutton "Return" action Return() xpos 100 ypos -100


User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: [Solved] Help with CG gallery!

#2 Post by Divona »

About the grid overfull, it's likely to be from textbutton you put inside the grid the size of 2, therefore textbutton is number 3 that overfull the grid. Here is what it should be:

Code: Select all

    grid 1 2:

        xfill True
        yfill True

        # Call make_button to show a particular button.
        add g.make_button("Gallery_b_1", "CG/CGlock.jpg", xalign=0.5, yalign=0.5 )
        add g.make_button("Gallery_b_2", "CG/CGlock.jpg", xalign=0.5, yalign=0.5 )
     

    # The screen is responsible for returning to the main menu. It could also
    # navigate to other gallery screens.
    textbutton "Return" action Return() xalign 0.5 yalign 0.5
Alternatively, you could just set grid to hold 3 items:

Code: Select all

    grid 1 3:
Completed:
Image

Post Reply

Who is online

Users browsing this forum: No registered users