CG Gallery using code?

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
Rinzamakani
Regular
Posts: 74
Joined: Wed Aug 16, 2017 3:23 pm
Completed: Love's Apathy (Ciro route), A Frigid Space, Telechronic Static
Projects: Love's Apathy (Full)
itch: rinzamakani.itch.io
Contact:

CG Gallery using code?

#1 Post by Rinzamakani »

Hello. I've been trying to make a gallery for four characters for about a week. Every gallery code I've tried online spits out errors. The original code a friend gave is the one below:

Code: Select all

##ToDo: Make sure the button which leads to the gallery has the action listed below.
button:
    action [ShowMenu("gallery_navigation"), Show("gallery")

################################################################################
## Gallery screen
################################################################################

## Gallery Images
init python:

    g = Gallery()

    ## Your Gallery Items 
    ## ToDo: Copy Paste these two lines and add your buttonname and imagename/path of the cg, do that for all cg's.
    g.button("Gallery_Button_Name")
    g.unlock_image("Gallery_Image.png")

    g.transition = dissolve

## Variable for CG Page
default cg_page = 1
## Gallery Part 1, Navigation
screen gallerynavigation():

    ## Background Image of the Gallery
    ## ToDo: Add your gallery background.
    add "Background.png"

    vbox:
        xalign 0.0
        yalign 0.5
        spacing 20

        ## Your Gallery Pages (1-3). 
        ## ToDo: Copy/Paste and change the number if you need more pages. Names can be anything from numbers to character names.
        textbutton ("1") action SetVariable("cgpage", 1)
        textbutton ("2") action SetVariable("cgpage", 2)
        textbutton ("3") action SetVariable("cgpage", 3)

    textbutton ("Return") action [Return(), Hide("gallery_navigation")]

## Gallery Part 2, Content
screen gallery():

    zorder 100
    tag menu

    ## Gallery Buttons for Page 1, CG 1-9. 
    ## ToDo: Copy/Paste this section and change the number for the second, third etc page.
    if cg_page == 1:

        grid 3 3:

            ## Adjust these numbers as you wish.
            xalign 0.5
            yalign 0.5
            xspacing 20
            yspacing 20

            ## The actual gallery content.
            ## ToDo: Add 9 buttons from the ones you created by writting the name and adding the other info in or add null for any empty slots in case the grid wont be full.
            add g.make_button("Gallery_Button_Name", "Gallery_Image_Thumbnail.png", "Gallery_Locked_Thumbnail.png")
The error I get with this code is:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/gallery.rpy", line 3: is not terminated with a newline. (Check strings and parenthesis.)
        action [ShowMenu("gallery_navigation"), Show("gallery")

Ren'Py Version: Ren'Py 7.1.3.1092
Wed Feb 13 13:04:06 2019
I'm using imagemaps with the current gallery button looking like this:

Code: Select all

hotspot (778, 647, 274, 52) action ShowMenu ("gallery")
Is there any way I can achieve a CG gallery with only code? I may be misplacing something. I'm not sure. Sorry. This is my first time trying to get a gallery in my game.

User avatar
wyverngem
Miko-Class Veteran
Posts: 615
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Re: CG Gallery using code?

#2 Post by wyverngem »

The error is in line three. You need to add ] at the end.

Code: Select all

action [ShowMenu("gallery_navigation"), Show("gallery")]

User avatar
Rinzamakani
Regular
Posts: 74
Joined: Wed Aug 16, 2017 3:23 pm
Completed: Love's Apathy (Ciro route), A Frigid Space, Telechronic Static
Projects: Love's Apathy (Full)
itch: rinzamakani.itch.io
Contact:

Re: CG Gallery using code?

#3 Post by Rinzamakani »

wyverngem wrote: Wed Feb 13, 2019 5:22 pm The error is in line three. You need to add ] at the end.

Code: Select all

action [ShowMenu("gallery_navigation"), Show("gallery")]
I see. Thank you. After I added that, however, it gives me this:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/gallery.rpy", line 2: expected statement.
    button:
          ^

Ren'Py Version: Ren'Py 7.1.3.1092
Wed Feb 13 15:43:34 2019

User avatar
Sunlit-Dreamer
Veteran
Posts: 400
Joined: Thu Sep 22, 2011 12:41 am
Completed: NaNo2015 Bedtime, NaNo2016 The Doll and the Spider, NaNo2017 What's Your Name?, NaNo2018 Painting Your Skin, NaNo2019 Home's Embrace, NaNo2020 Molly
Projects: NaNo2021 Cracked Moonstone
Deviantart: Sunlit-Dreamer
itch: Sunlit-Dreamer
Location: Lala land~
Contact:

Re: CG Gallery using code?

#4 Post by Sunlit-Dreamer »

Ahh, you need to add the button to the navigation menu, like so.

Code: Select all

screen navigation():

    vbox:
        style_prefix "navigation"

        xpos gui.navigation_xpos
        yalign 0.5

        spacing gui.navigation_spacing

        if main_menu:

            textbutton _("Start") action Start()

        else:

            textbutton _("History") action ShowMenu("history")

            textbutton _("Save") action ShowMenu("save")

        textbutton _("Load") action ShowMenu("load")

        textbutton _("Preferences") action ShowMenu("preferences")
        
        textbutton _("Gallery") action [ShowMenu("gallery_navigation"), Show("gallery")]

        if _in_replay:

            textbutton _("End Replay") action EndReplay(confirm=True)

        elif not main_menu:

            textbutton _("Main Menu") action MainMenu()

        textbutton _("About") action ShowMenu("about")
ImageImageImageImage

User avatar
Rinzamakani
Regular
Posts: 74
Joined: Wed Aug 16, 2017 3:23 pm
Completed: Love's Apathy (Ciro route), A Frigid Space, Telechronic Static
Projects: Love's Apathy (Full)
itch: rinzamakani.itch.io
Contact:

Re: CG Gallery using code?

#5 Post by Rinzamakani »

Sunlit-Dreamer wrote: Wed Feb 13, 2019 6:20 pm Ahh, you need to add the button to the navigation menu, like so.

Code: Select all

screen navigation():

    vbox:
        style_prefix "navigation"

        xpos gui.navigation_xpos
        yalign 0.5

        spacing gui.navigation_spacing

        if main_menu:

            textbutton _("Start") action Start()

        else:

            textbutton _("History") action ShowMenu("history")

            textbutton _("Save") action ShowMenu("save")

        textbutton _("Load") action ShowMenu("load")

        textbutton _("Preferences") action ShowMenu("preferences")
        
        textbutton _("Gallery") action [ShowMenu("gallery_navigation"), Show("gallery")]

        if _in_replay:

            textbutton _("End Replay") action EndReplay(confirm=True)

        elif not main_menu:

            textbutton _("Main Menu") action MainMenu()

        textbutton _("About") action ShowMenu("about")
Thank you! That seems to have helped with that, but now I'm getting this error.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/gallery.rpy", line 42, in execute
    screen gallery():
  File "game/gallery.rpy", line 42, in execute
    screen gallery():
  File "game/gallery.rpy", line 49, in execute
    if cg_page == 1:
  File "game/gallery.rpy", line 51, in execute
    grid 3 3:
  File "game/gallery.rpy", line 61, in execute
    add g.make_button("Gallery_Button_Name", "Gallery_Image_Thumbnail.png", "Gallery_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 "C:\Users\xion1\Documents\renpy-6.99.13-sdk\renpy\ast.py", line 881, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\xion1\Documents\renpy-6.99.13-sdk\renpy\python.py", line 1913, 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 "C:\Users\xion1\Documents\renpy-6.99.13-sdk\renpy\ui.py", line 289, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\Users\xion1\Documents\renpy-6.99.13-sdk\renpy\display\core.py", line 2672, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "C:\Users\xion1\Documents\renpy-6.99.13-sdk\renpy\display\core.py", line 3059, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "C:\Users\xion1\Documents\renpy-6.99.13-sdk\renpy\display\core.py", line 531, in visit_all
    d.visit_all(callback, seen)
  File "C:\Users\xion1\Documents\renpy-6.99.13-sdk\renpy\display\core.py", line 531, in visit_all
    d.visit_all(callback, seen)
  File "C:\Users\xion1\Documents\renpy-6.99.13-sdk\renpy\display\core.py", line 531, in visit_all
    d.visit_all(callback, seen)
  File "C:\Users\xion1\Documents\renpy-6.99.13-sdk\renpy\display\core.py", line 531, in visit_all
    d.visit_all(callback, seen)
  File "C:\Users\xion1\Documents\renpy-6.99.13-sdk\renpy\display\screen.py", line 424, in visit_all
    callback(self)
  File "C:\Users\xion1\Documents\renpy-6.99.13-sdk\renpy\display\core.py", line 3059, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "C:\Users\xion1\Documents\renpy-6.99.13-sdk\renpy\display\screen.py", line 434, in per_interact
    self.update()
  File "C:\Users\xion1\Documents\renpy-6.99.13-sdk\renpy\display\screen.py", line 619, in update
    self.screen.function(**self.scope)
  File "game/gallery.rpy", line 42, in execute
    screen gallery():
  File "game/gallery.rpy", line 42, in execute
    screen gallery():
  File "game/gallery.rpy", line 49, in execute
    if cg_page == 1:
  File "game/gallery.rpy", line 51, in execute
    grid 3 3:
  File "game/gallery.rpy", line 61, in execute
    add g.make_button("Gallery_Button_Name", "Gallery_Image_Thumbnail.png", "Gallery_Locked_Thumbnail.png")
  File "<screen language>", line 61, in <module>
AttributeError: 'ADVCharacter' object has no attribute 'make_button'

Windows-8-6.2.9200
Ren'Py 7.1.3.1092
Game 1.0
Wed Feb 13 21:20:58 2019

User avatar
Sunlit-Dreamer
Veteran
Posts: 400
Joined: Thu Sep 22, 2011 12:41 am
Completed: NaNo2015 Bedtime, NaNo2016 The Doll and the Spider, NaNo2017 What's Your Name?, NaNo2018 Painting Your Skin, NaNo2019 Home's Embrace, NaNo2020 Molly
Projects: NaNo2021 Cracked Moonstone
Deviantart: Sunlit-Dreamer
itch: Sunlit-Dreamer
Location: Lala land~
Contact:

Re: CG Gallery using code?

#6 Post by Sunlit-Dreamer »

Ahh, I see now. It seems you didn't edit the code your friend gave you? You have to add in the images you plan to use for the background and thumbnails. You would also have to copy and paste extra lines for each cg you want in your gallery. Whatever you named those images, you write.

I think something like this, since I can't access my old projects. I haven't used null yet, but I did try to make a tiny example. You would have to tinker with that to get the height right.

Edit: I looked in the Renpy Cookbook and saw a thread for an extras gallery by gas. It seems you don't need to add height to null. So I edited accordingly.

Code: Select all

## Gallery Part 2, Content
screen gallery():

    zorder 100
    tag menu

    ## Gallery Buttons for Page 1, CG 1-9. 
    ## ToDo: Copy/Paste this section and change the number for the second, third etc page.
    if cg_page == 1:

        grid 3 3:

            ## Adjust these numbers as you wish.
            xalign 0.5
            yalign 0.5
            xspacing 20
            yspacing 20

            ## The actual gallery content.
            ## ToDo: Add 9 buttons from the ones you created by writting the name and adding the other info in or add null for any empty slots in case the grid wont be full.
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG1.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG2.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG3.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG4.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG5.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG6.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG7.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG8.png", "Gallery_Locked_Thumbnail.png")
            null

    if cg_page == 2:

        grid 3 3:

            xalign 0.5
            yalign 0.5
            xspacing 20
            yspacing 20

		
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG10.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG11.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG12.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG13.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG14.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG15.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG16.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG17.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailCG18.png", "Gallery_Locked_Thumbnail.png")
            
    if cg_page == 3:

        grid 3 3:

            xalign 0.5
            yalign 0.5
            xspacing 20
            yspacing 20

            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailBG1.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailBG2.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailBG3.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailBG4.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailBG5.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailBG6.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailBG7.png", "Gallery_Locked_Thumbnail.png")
            add g.make_button("Gallery_Button_Name", "Gallery_Image_ThumbnailBG8.png", "Gallery_Locked_Thumbnail.png")
            null
Hopefully this will work if my memory's right.
ImageImageImageImage

Post Reply

Who is online

Users browsing this forum: No registered users