[Solved!]Multiple images in a 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
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

[Solved!]Multiple images in a CG Gallery

#1 Post by yuucie »

I decided to bite the bullet and attempt a CG gallery which I've been dreading.

My problem so far is having variations of a single CG, and wanting both of them to show up in one thumbnail (aka: 1 thumbnail for CG1, when clicked shows CG1a, clicked again transitions to CG1b, clicked again returns to gallery), or just multiple images of a button as defined in the cookbook.

I've used The quick and easy CG Gallery code here, and read his reply to multiple images here, which didn't do anything.

So I looked up past questions on multiple images and found this thread and attempted to merge it with the quick and easy CG Gallery code, but it's been popping up errors about strings and such and I have no idea where I went wrong.

I'm guessing the issue is defining two images in that [ ] when adding items to the gallery. The code isn't reading it since it's a string.

Here's my code so far:

Code: Select all

init python:
    #Galleries settings - start
    #list the CG gallery images here:
    gallery_Char1cg_items = [["CG1a", "CG1b"], "cg2", "cg3", "cg4", "cg5"]

    #how many rows and columns in the gallery screens?
    gal_rows = 3
    gal_cols = 3
    #thumbnail size in pixels:
    thumbnail_x = 200
    thumbnail_y = 150
    #the setting above (267x150) will work well with 16:9 screen ratio. Make sure to adjust it, if your are using 4:3 or something else.
    #Galleries settings - end
    
    gal_cells = gal_rows * gal_cols    
    g_cg = Gallery()

    for index, imgList in enumerate(gallery_Char1cg_items):
        g_cg.button(str(index) + " butt")
        for gal_item in imgList:

            if isinstance(gal_item, basestring): 
                g_cg.unlock(gal_item)

            else:
                g_cg.unlock(gal_item[0]. gal_item[1])

init +1 python:

    #Here we create the thumbnails. We create a grayscale thumbnail image for BGs, but we use a special "locked" image for CGs to prevent spoilers.

    for gal_item in gallery_Char1cg_items:
        renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))
and this is the error:

I'm sorry, but an uncaught exception occurred.

While executing init code:
File "game/screens.rpy", line 649, in script
init +1 python:
File "game/screens.rpy", line 655, in <module>
renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))
TypeError: can only concatenate list (not "str") to list



Thanks in advance for any help OTL I've been working this code for 10 hours now

EDIT I'm an idiot and forgot to include the codes where the error is popping up OTL

User avatar
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: [Solved!]Multiple images in a CG Gallery

#2 Post by yuucie »

Fixed!! Every time I ask a question I often end up solving it myself in a few hours orz.

I don't know how I fixed it AT ALL (basically tried nearly everything I could think of), so here's the fixed code for anyone in the future who wants to pull it off too:

Code: Select all

init python:
    #Galleries settings - start
    #list the CG gallery images here:

    gallery_Char1cg_items = [["CG1a", "CG1b"], ["cg2"], ["cg3"], ["cg4"], ["cg5"]]
    butImgs = [];

    #how many rows and columns in the gallery screens?
    gal_rows = 3
    gal_cols = 3

    #thumbnail size in pixels:
    thumbnail_x = 200
    thumbnail_y = 150

    #the setting above (267x150) will work well with 16:9 screen ratio. Make sure to adjust it, if your are using 4:3 or something else.

    #Galleries settings - end

    cur_page = 0

    gal_cells = gal_rows * gal_cols    
    g_cg = Gallery()
    for index, imgList in enumerate(gallery_Char1cg_items):
        g_cg.button(str(index) + "button")
        for gal_item in imgList:
            if isinstance(gal_item, basestring): 
                g_cg.unlock_image(gal_item)
            else:
                g_cg.unlock_image(gal_item[0]. gal_item[1])
    g_cg.transition = dissolve

init +1 python:

    #Here we create the thumbnails. We create a grayscale thumbnail image for BGs, but we use a special "locked" image for CGs to prevent spoilers.
    
    for index, gal_item in enumerate(gallery_Char1cg_items):
        if not butImgs:
            renpy.image(gallery_Char1cg_items[index][0] +"buttonImg", im.Scale(ImageReference(gallery_Char1cg_items[index][0]), thumbnail_x, thumbnail_y))
        else:
            renpy.image(butImgs[index]+"buttonImg", im.Scale(ImageReference(butImgs[index]), thumbnail_x, thumbnail_y))   


screen gallery:
    tag menu

    imagemap:
        ground "UI/CG Gallery idle.png"
        idle "UI/CG Gallery idle.png"
        hover "UI/CG Gallery hover.png"
        
        #Char1
        hotspot (20, 136, 217, 59) action ShowMenu("Char1_Gallery") hovered Play ("first", "sound/hover3.mp3")
        #Char2
        hotspot (20, 217, 217, 59) action ShowMenu("Char2_Gallery") hovered Play ("second", "sound/hover3.mp3")
        #Return
        hotspot (44, 708, 164, 41) action Return() hovered Play ("second", "sound/hover3.mp3")
        

screen Char1_Gallery:
    tag menu

    imagemap:
        ground "UI/CG Gal Char1 idle.png"
        idle "UI/CG Gal Char1 idle.png"
        hover "UI/CG Gallery hover.png"
        
        #Char1
        hotspot (20, 136, 217, 59) action ShowMenu("Char1_Gallery") hovered Play ("first", "sound/hover3.mp3")
        #Char2
        hotspot (20, 217, 217, 59) action ShowMenu("Char2_Gallery") hovered Play ("second", "sound/hover3.mp3")
        #Return
        hotspot (44, 708, 164, 41) action Return() hovered Play ("second", "sound/hover3.mp3")
        

    frame background None xpos 10:
        grid gal_rows gal_cols:
            ypos 0.2425
            xpos 0.336
            xmaximum 700
            ymaximum 570
            xfill True
            yfill True
            $ i = 0
            
            for index in range(cur_page*gal_cells,min(cur_page*gal_cells+gal_cells,len(gallery_Char1cg_items))):
                $ i += 1
                if not butImgs:
                    add g_cg.make_button(str(index)+"button", gallery_Char1cg_items[index][0] +"buttonImg", im.Scale("UI/unlockedCG.png", thumbnail_x, thumbnail_y), xalign=0.5, yalign=0.5, idle_border=None, background=None, bottom_margin=24)
                else:
                    add g_cg.make_button(str(index) + "button", butImgs[index]+ "buttonImg", im.Scale("UI/unlockedCG.png", thumbnail_x, thumbnail_y), xalign=0.5, yalign=0.5, idle_border=None, background=None, bottom_margin=24)
            
            for j in range(i, (cg_page+1)*gal_cells): #we need this to fully fill the grid
                null

###screen Char2_Gallery: etc, basically a copy of the above but just changed to Char 2

Post Reply

Who is online

Users browsing this forum: DewyNebula, IVANtheVN