Code for character 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
aitha
Newbie
Posts: 5
Joined: Fri Sep 20, 2019 4:03 am
Contact:

Code for character gallery

#1 Post by aitha »

I am super dumb in coding. :cry: :oops:
I want an easy code for adding the gallery into the game.
All images are unlocked no locking is needed.
I Just want to show group images and I want user clicked on it should show image fullscreen.
I tried a bunch of youtube tutorials and ren'py documentation everything getting error. (I am using the latest version of ren'py SDK.)

And I tried Per-Character Gallery (+ Multiple Pages) by mitoky from Ren'Py Cookbook. But I get an error of AttributeError: 'ADVCharacter' object has no attribute 'make_button'.

viewtopic.php?f=51&t=55597

Please Help Me. I will be grateful.
Have a nice day.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/gallery.rpy", line 49, in execute
    screen gallery_a():
  File "game/gallery.rpy", line 49, in execute
    screen gallery_a():
  File "game/gallery.rpy", line 63, in execute
    showif cg_page_a == 1:
  File "game/gallery.rpy", line 64, in execute
    grid 2 2:
  File "game/gallery.rpy", line 70, in execute
    add g.make_button("CG_Button_Name", "path/Unlocked_Thumbnail.png", "path/Locked_Thumbnail.png")
AttributeError: 'ADVCharacter' object has no attribute 'make_button'

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

Full traceback:
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in script
    python hide:
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\ast.py", line 912, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\python.py", line 2004, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in <module>
    python hide:
  File "renpy/common/_layout/screen_main_menu.rpym", line 35, in _execute_python_hide
    ui.interact()
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\ui.py", line 295, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\core.py", line 2699, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\core.py", line 3091, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\screen.py", line 430, in visit_all
    callback(self)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\core.py", line 3091, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\screen.py", line 440, in per_interact
    self.update()
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\screen.py", line 625, in update
    self.screen.function(**self.scope)
  File "game/gallery.rpy", line 49, in execute
    screen gallery_a():
  File "game/gallery.rpy", line 49, in execute
    screen gallery_a():
  File "game/gallery.rpy", line 63, in execute
    showif cg_page_a == 1:
  File "game/gallery.rpy", line 64, in execute
    grid 2 2:
  File "game/gallery.rpy", line 70, in execute
    add g.make_button("CG_Button_Name", "path/Unlocked_Thumbnail.png", "path/Locked_Thumbnail.png")
  File "<screen language>", line 70, in <module>
AttributeError: 'ADVCharacter' object has no attribute 'make_button'

Windows-8-6.2.9200
Ren'Py 7.3.2.320
Pure Love 0.1
Fri Sep 20 15:17:51 2019

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Code for character gallery

#2 Post by RicharDann »

Judging by the error message you probably have created a character named g, and that's conflicting with the Gallery object, which is also called g in the Gallery example.

Code: Select all

init python:
	g = Gallery() # the gallery is created here, with g as the name 
	
	# Gallery code continues below

Code: Select all

define g = Character("Gina") # a Character for Ren'py dialogue, also named g.
As both are named the same, renpy gets confused and tries to add something that's meant for the gallery to the character, and as that's not possible, it throws an error.
To fix this, try renaming that character to something else, alternatively you would have to change all the gallery code but it will be much easier for you to just change the character.
The most important step is always the next one.

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Code for character gallery

#3 Post by isobellesophia »

you can rename it into

Code: Select all

i = Gallery()
instead, any letter can do just to make sure that the g wont be written, as Dann said.
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Code for character gallery

#4 Post by namastaii »

Don't change it to something else as you'll have to change g to something else in the entire code. Just make sure you haven't defined g somewhere else like a character as Richardann stated

User avatar
isobellesophia
Miko-Class Veteran
Posts: 979
Joined: Mon Jan 07, 2019 2:55 am
Completed: None
Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: Child Creation
Location: Philippines, Mindanao
Contact:

Re: Code for character gallery

#5 Post by isobellesophia »

Well, i did put any letter of it, no errors were occured, so i guess its fine whether if putting a letter, or put it a g instead.
I am a friendly user, please respect and have a good day.


Image

Image


User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Code for character gallery

#6 Post by namastaii »

Code: Select all

init python:

    g = Gallery()

    g.button("CG1_Button")
    g.unlock_image("CG1")

    g.button("CG2_Button")
    g.unlock_image("CG2")

    g.button("CG3_Button")
    g.unlock_image("CG3")

    g.button("CG4_Button")
    g.unlock_image("CG4")

    ## and so on...

    g.transition = dissolve
You can put any letter you want as long as you change the entire code to that letter or it won't work. We've defined g as the gallery so we can call these commands with g.

so my advice would be if you don't want to change the code or over complicate things, define your other g as something else

aitha
Newbie
Posts: 5
Joined: Fri Sep 20, 2019 4:03 am
Contact:

Re: Code for character gallery

#7 Post by aitha »

Thanks for the help. I changed my character variable to something new. But now I am getting this error.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/gallery.rpy", line 49, in execute
    screen gallery_a():
  File "game/gallery.rpy", line 49, in execute
    screen gallery_a():
  File "game/gallery.rpy", line 63, in execute
    showif cg_page_a == 1:
  File "game/gallery.rpy", line 64, in execute
    grid 2 2:
  File "game/gallery.rpy", line 69, in execute
    add g.make_button("Button", "images/Next.png", "images/Next.png")
  File "renpy/common/00gallery.rpy", line 382, in make_button
    action = self.Action(name)
  File "renpy/common/00gallery.rpy", line 335, in Action
    raise Exception("{0!r} is not a button defined in this gallery.".format(name))
Exception: u'Button' is not a button defined in this gallery.

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

Full traceback:
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in script
    python hide:
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\ast.py", line 912, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\python.py", line 2004, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in <module>
    python hide:
  File "renpy/common/_layout/screen_main_menu.rpym", line 35, in _execute_python_hide
    ui.interact()
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\ui.py", line 295, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\core.py", line 2699, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\core.py", line 3091, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\core.py", line 541, in visit_all
    d.visit_all(callback, seen)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\screen.py", line 430, in visit_all
    callback(self)
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\core.py", line 3091, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\screen.py", line 440, in per_interact
    self.update()
  File "D:\Game Development\Renpy\renpy-7.3.0-sdk\renpy\display\screen.py", line 625, in update
    self.screen.function(**self.scope)
  File "game/gallery.rpy", line 49, in execute
    screen gallery_a():
  File "game/gallery.rpy", line 49, in execute
    screen gallery_a():
  File "game/gallery.rpy", line 63, in execute
    showif cg_page_a == 1:
  File "game/gallery.rpy", line 64, in execute
    grid 2 2:
  File "game/gallery.rpy", line 69, in execute
    add g.make_button("Button", "images/Next.png", "images/Next.png")
  File "<screen language>", line 69, in <module>
  File "renpy/common/00gallery.rpy", line 382, in make_button
    action = self.Action(name)
  File "renpy/common/00gallery.rpy", line 335, in Action
    raise Exception("{0!r} is not a button defined in this gallery.".format(name))
Exception: u'Button' is not a button defined in this gallery.

Windows-8-6.2.9200
Ren'Py 7.3.2.320
Pure Love 0.1
Sat Sep 21 16:33:46 2019
This is my code:-

Code: Select all

#screen gallery: tag menu add "black"
###############################################################################################################################################
## Copy/Paste And Follow Instructions!
## DONT forget to define your CG's used in the gallery, like said at the very top of the Tutorial!
###############################################################################################################################################

####################################################################################
## Button to Copy/Paste into the Main Menu in screeny.rpy into the right place. No Edits Necsassary.
####################################################################################

#textbutton _("Gallery") action [ShowMenu("gallery_navigation"), Show("gallery_a")]

####################################################################################
## Gallery Elements and Gallerys. Copy/Paste this at the end of screens.rpy
####################################################################################

init python:

    g = Gallery()

    ## Edit this with your stuff and create the rest according to tutorial.
    g.button("Button_Name")
    g.unlock_image("CG_Image")

    g.transition = dissolve

screen gallery():

    ## Change with your image
    add "bg_gallery"

    vbox:
        style_prefix "gallery_nav"

        ## Gallery Navigation to Character A, Character B and Character C gallery.
        textbutton _("char1") action Show("gallery_a")
        textbutton _(" char2") action Show("gallery_b")
        textbutton _(" char3") action Show("gallery_c")
        textbutton _("char4") action Show("gallery_d")
        textbutton _("char5") action Show("gallery_e")
    textbutton _("Return") action [Return(), Hide("gallery")] xalign 0.97 yalign 0.95

## The position of the vertical box containing the gallery navigation buttons
style gallery_nav_vbox:
    xalign 0.5
    yalign 0.5
    spacing 100

screen gallery_a():

    default cg_page_a = 1

    zorder 100
    tag menu

    hbox:
        style_prefix "gallery_stuff"

        ## Our buttons for the pages of Character A's Gallery section.
        textbutton _("1") action SetLocalVariable("cg_page_a", 1)
        textbutton _("2") action SetLocalVariable("cg_page_a", 2)

    showif cg_page_a == 1:
        grid 2 2:
            style_prefix "gallery_stuff"

            ## Replace one null with one button created according to this structure:
            ## add g.make_button("CG_Button_Name", "path/Unlocked_Thumbnail.png", "path/Locked_Thumbnail.png")
            add g.make_button("Button", "images/Next.png", "images/Next.png")
            null
            null
            null

    elif cg_page_a == 2:
        grid 2 2:
            style_prefix "gallery_stuff"

            ## Replace one null with one button created according to this structure:
            ## add g.make_button("CG_Button_Name", "path/Unlocked_Thumbnail.png", "path/Locked_Thumbnail.png")
            null
            null
            null
            null

screen gallery_b():

    default cg_page_b = 1

    zorder 100
    tag menu

    hbox:
        style_prefix "gallery_stuff"

        ## Our buttons for the pages of Character B's Gallery section.
        textbutton _("1") action SetLocalVariable("cg_page_b", 1)
        textbutton _("2") action SetLocalVariable("cg_page_b", 2)

    showif cg_page_b == 1:
        grid 2 2:
            style_prefix "gallery_stuff"

            ## Replace one null with one button created according to this structure:
            ## add g.make_button("CG_Button_Name", "path/Unlocked_Thumbnail.png", "path/Locked_Thumbnail.png")
            null
            null
            null
            null

    elif cg_page_b == 2:
        grid 2 2:
            style_prefix "gallery_stuff"

            ## Replace one null with one button created according to this structure:
            ## add g.make_button("CG_Button_Name", "path/Unlocked_Thumbnail.png", "path/Locked_Thumbnail.png")
            null
            null
            null
            null

screen gallery_c():

    default cg_page_c = 1

    zorder 100
    tag menu

    hbox:
        style_prefix "gallery_stuff"

        ## Our buttons for the pages of Character C's Gallery section.
        textbutton _("1") action SetLocalVariable("cg_page_c", 1)
        textbutton _("2") action SetLocalVariable("cg_page_c", 2)

    showif cg_page_c == 1:
        grid 2 2:
            style_prefix "gallery_stuff"

            ## Replace one null with one button created according to this structure:
            ## add g.make_button("CG_Button_Name", "path/Unlocked_Thumbnail.png", "path/Locked_Thumbnail.png")
            null
            null
            null
            null

    elif cg_page_c == 2:
        grid 2 2:
            style_prefix "gallery_stuff"

            ## Replace one null with one button created according to this structure:
            ## add g.make_button("CG_Button_Name", "path/Unlocked_Thumbnail.png", "path/Locked_Thumbnail.png")
            null
            null
            null
            null

screen gallery_d():

    default cg_page_d = 1

    zorder 100
    tag menu

    hbox:
        style_prefix "gallery_stuff"

        ## Our buttons for the pages of Character d's Gallery section.
        textbutton _("1") action SetLocalVariable("cg_page_d", 1)
        textbutton _("2") action SetLocalVariable("cg_page_d", 2)

    showif cg_page_d == 1:
        grid 2 2:
            style_prefix "gallery_stuff"

            ## Replace one null with one button created according to this structure:
            ## add g.make_button("CG_Button_Name", "path/Unlocked_Thumbnail.png", "path/Locked_Thumbnail.png")
            null
            null
            null
            null

    elif cg_page_d == 2:
        grid 2 2:
            style_prefix "gallery_stuff"

            ## Replace one null with one button created according to this structure:
            ## add g.make_button("CG_Button_Name", "path/Unlocked_Thumbnail.png", "path/Locked_Thumbnail.png")
            null
            null
            null
            null

screen gallery_e():

    default cg_page_e = 1

    zorder 100
    tag menu

    hbox:
        style_prefix "gallery_stuff"

        ## Our buttons for the pages of Character e's Gallery section.
        textbutton _("1") action SetLocalVariable("cg_page_e", 1)
        textbutton _("2") action SetLocalVariable("cg_page_e", 2)

    showif cg_page_e == 1:
        grid 2 2:
            style_prefix "gallery_stuff"

            ## Replace one null with one button created according to this structure:
            ## add g.make_button("CG_Button_Name", "path/Unlocked_Thumbnail.png", "path/Locked_Thumbnail.png")
            null
            null
            null
            null

    elif cg_page_e == 2:
        grid 2 2:
            style_prefix "gallery_stuff"

            ## Replace one null with one button created according to this structure:
            ## add g.make_button("CG_Button_Name", "path/Unlocked_Thumbnail.png", "path/Locked_Thumbnail.png")
            null
            null
            null
            null

## The position of our gallery images.
style gallery_stuff_grid:
    xalign 0.5
    yalign 0.5
    xspacing 20
    yspacing 20

## The position of the page-buttons.
style gallery_stuff_hbox:
    xalign 0.5
    yanchor 0.9
    ypos 0.95


User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Code for character gallery

#8 Post by namastaii »

Did you follow all the steps on the tutorial? If so, I'd ask the author of the code since they posted it fairly recently

aitha
Newbie
Posts: 5
Joined: Fri Sep 20, 2019 4:03 am
Contact:

Re: Code for character gallery

#9 Post by aitha »

yeah and even I rechecked. no luck

Post Reply

Who is online

Users browsing this forum: Bing [Bot], decocloud, DewyNebula