[Solved]Defining Gallery buttons. Help!

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
Samitha
Newbie
Posts: 16
Joined: Wed Nov 13, 2019 5:21 pm
Projects: Princess Impersonator
itch: samitha-games
Contact:

[Solved]Defining Gallery buttons. Help!

#1 Post by Samitha »

Hello!

So, I am still a newbie and still struggling with Ren'Py... :(

I have this issue when implementing other gallery codes I've found out there. I have tried several but none have worked perfectly as of yet. The last one I implemented was this one right in this post: viewtopic.php?f=8&t=48056 with some tips from gas' gallery: viewtopic.php?t=50040

The problem lies in the definition of gallery buttons, or that's what Ren'Py says anyway :|

The following error occurs:

File "renpy/common/00gallery.rpy", line 330, in Action
raise Exception("{0!r} is not a button defined in this gallery.".format(name))
Exception: u'cg1button' is not a button defined in this gallery.

And this is my gallery code:

Code: Select all

init -1:
    image cg1  = "images/cg1.png"
    image cg2  = "images/cg2.png"
    image cg3  = "images/cg3.png"
    image cg4  = "images/cg4.png"
    image cgk1  = "images/cgk1.png"

init python:

    g = Gallery()
    g.button("cg1button")
    g.image("cg1")
    g.unlock("cg1")
    g.transition = dissolve

    g.button("cg2button")
    g.image("cg2")
    g.unlock("cg2")
    g.transition = dissolve

    g.button("cg3button")
    g.image("cg3")
    g.unlock("cg3")
    g.transition = dissolve

    g.button("cg4button")
    g.image("cg4")
    g.unlock("cg4")
    g.transition = dissolve

    g.button("cgk1button")
    g.image("cgk1")
    g.unlock("cgk1")
    g.transition = dissolve

    g.locked_button=("gui/locked_cg.png")

screen cg_gallery():
    tag menu
    add "gui/gallery_background.png"
    add "gui/gallery_title.png" xalign 0.5 yalign 0.1

    vbox:

        imagebutton auto "gui/gallery/knight_%s.png" xpos 210 ypos 270 action SetScreenVariable("curpage", "knight_cg")  alt _("Main Gallery")
        imagebutton auto "gui/gallery/prince_%s.png" xpos 210 ypos 270 action SetScreenVariable("curpage", "prince_cg")  alt _("Sean's Gallery")
        imagebutton auto "gui/gallery/cook_%s.png" xpos 210 ypos 270 action SetScreenVariable("curpage", "cook_cg")  alt _("Sean's Gallery")
        imagebutton auto "gui/gallery/extras_%s.png" xpos 210 ypos 270 action SetScreenVariable("curpage", "extras_cg")  alt _("Sean's Gallery")
        spacing 10

    vbox:
        imagebutton auto "gui/return_save_%s.png" xpos 160 ypos 950 action Return()


        grid 2 3:

            xfill True
            yfill True

            style_prefix "gslot"
            xalign 0.5
            yalign 0.5
            spacing 30

            add g.make_button("cg1button", "images/cg1_thumb.png")
            add g.make_button("cg2button", "images/cg2_thumb.png")
            add g.make_button("cg3button", "images/cg3_thumb.png")
            add g.make_button("cg4button", "images/cg4_thumb.png")
            null
            null

style gslot:
    xsize 256
    ysize 144
I still haven't made the other screens that divide the cgs per character, so just ignore that, I guess xD?

I really don't know what I'm doing wrong :oops:

Thanks in advance! :D :D
Last edited by Samitha on Wed Mar 04, 2020 5:01 pm, edited 1 time in total.

User avatar
Jackkel Dragon
Veteran
Posts: 283
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: Defining Gallery buttons. Help!

#2 Post by Jackkel Dragon »

I believe the main issue here is that the button needs to have the same name as the ID of the unlock. For instance:

Code: Select all

    g.button("cg1")
    g.image("cg1")
    g.unlock("cg1")
I don't recall enough of the underlying data structure, but I wrote my gallery that way and it works for me. Maybe it's a coincidence and I just got it right through luck, but I think this is what is happening:

- Create a button with the ID "cg1"
- Add the image "cg1" to the last button created
- Unlock the button with the ID "cg1" Add the unlock condition "player has seen 'cg1'" to the last button created

I'll have to double-check the documentation to be sure, though.

Edit: I checked the documentation and the Ren'Py files, and I think my descriptions are more accurate now. Unfortunately, I no longer am sure what may be wrong with the code...
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Defining Gallery buttons. Help!

#3 Post by gas »

Remove that init -1 to define images.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Defining Gallery buttons. Help!

#4 Post by Imperf3kt »

Your buttons have an image to show when clicked, and a thumbnail, but no 'locked' image. Could that be related?


Having the images defined in a -1 init shouldn't harm anything, and from my testing was necessary for the images to be defined before the screen, otherwise renpy threw an undefined exception.

Reading over the linked thread, I think it's time I got around to finishing my renpy gallery tutorial and updating it for the latest version of renpy.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Samitha
Newbie
Posts: 16
Joined: Wed Nov 13, 2019 5:21 pm
Projects: Princess Impersonator
itch: samitha-games
Contact:

Re: Defining Gallery buttons. Help!

#5 Post by Samitha »

Thank you all for your suggestions!

But they didn't really work, the same error keeps popping up.
- Create a button with the ID "cg1"
- Add the image "cg1" to the last button created
- Unlock the button with the ID "cg1" Add the unlock condition "player has seen 'cg1'" to the last button created
I did exactly as you suggested. I think it's something like this:

Code: Select all

init python:

    g = Gallery()
    g.button("cg1")
    g.image("cg1")
    g.condition("persistent.unlock_cg1")
    g.transition = dissolve
And it didn't work :(
Remove that init -1 to define images.
Did this too, but nothing changed.
Your buttons have an image to show when clicked, and a thumbnail, but no 'locked' image. Could that be related?
And sadly no, I included it, but it's still not working:

Code: Select all

add g.make_button("cg1", "images/cg1_thumb.png", "gui/locked_cg.png")
Are other parts of the code related to the gallery? Could some other screen be affecting it? Or something else along those lines?
Reading over the linked thread, I think it's time I got around to finishing my renpy gallery tutorial and updating it for the latest version of renpy.
Yes! That would be highly appreciated :D !!

User avatar
Jackkel Dragon
Veteran
Posts: 283
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: Defining Gallery buttons. Help!

#6 Post by Jackkel Dragon »

Is it possible you used "g" as a variable somewhere else? The error suggests that the button was never created, but you use the right spelling for both uses of the button name. Maybe open the debug console and see what the value of "g.buttons" is. If that returns an error, then maybe g was set to something else after initialization.
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

User avatar
Samitha
Newbie
Posts: 16
Joined: Wed Nov 13, 2019 5:21 pm
Projects: Princess Impersonator
itch: samitha-games
Contact:

Re: Defining Gallery buttons. Help!

#7 Post by Samitha »

Is it possible you used "g" as a variable somewhere else?
Yes! That was it! I hadn't noticed and had repeated the same

Code: Select all

g = Gallery()
twice in another file.

Sorry for the newbie type of mistake, and thank you for your help! :D

User avatar
Jackkel Dragon
Veteran
Posts: 283
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: [Solved]Defining Gallery buttons. Help!

#8 Post by Jackkel Dragon »

Glad you managed to figure out the issue. Having such short variable/object names can be risky, but that does happen to be how the examples tend to show setting up a gallery. The other call to set "g" to a new gallery object must have been run by the program after the one you intended to be run, thus erasing the original gallery for a blank one. Hopefully you don't run into any more issues like that.
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

User avatar
Samitha
Newbie
Posts: 16
Joined: Wed Nov 13, 2019 5:21 pm
Projects: Princess Impersonator
itch: samitha-games
Contact:

Re: [Solved]Defining Gallery buttons. Help!

#9 Post by Samitha »

Thank you for explaining it thoroughly and helping me this far! I hope so too, but being new in Renp'y is bound to make me learn the hard way. Best wishes to you too!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Dark79, Google [Bot]