Manually unlocking gallery item

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
GoldenMagician
Newbie
Posts: 19
Joined: Mon Mar 19, 2018 12:44 pm
Contact:

Manually unlocking gallery item

#1 Post by GoldenMagician »

I've been trying to manually unlock gallery items. I used gallery from here: viewtopic.php?f=8&t=48056#p477176
Basically, I have something like this:

Code: Select all

init-1:
    image bg sc01 = "testing.png"
    image bg sc02 = "test.png"
    image bg sc03 = "test.png"
    image bg sc04 = "test.png"
    image bg sc05 = "test.png"
    image bg sc06 = "test.png"
    image bg sc07 = "test.png"
    image bg sc08 = "test.png"
    image bg sc09 = "test.png"
    image bg sc10 = "test.png"
    image bg sc11 = "test.png"
    image bg sc12 = "test.png"


init python:
    #Galleries settings - start
    #list the CG gallery images here:
    gallery_cg_items = ["bg sc01", "bg sc02", "bg sc03", "bg sc04", "bg sc05", "bg sc06", "bg sc07", "bg sc08", "bg sc09", "bg sc10", "bg sc11", "bg sc12"]
    #how many rows and columns in the gallery screens?
    gal_rows = 10
    gal_cols = 4
    #thumbnail size in pixels:
    thumbnail_x = 182
    thumbnail_y = 100
    #the setting above will work well with 4:3 screen ratio. Make sure to adjust it, if your are using 16:9 (such as 267x150) or something else.
    #Galleries settings - end

    gal_cells = gal_rows * gal_cols
    g_cg = Gallery()
    for gal_item in gallery_cg_items:
        g_cg.button(gal_item + " butt")
        g_cg.image(gal_item)
        g_cg.unlock(gal_item)
    g_cg.transition = fade
    cg_page=0

init +1 python:
    #Here we create the thumbnails. We use a special "locked" image for CGs to prevent spoilers.
    for gal_item in gallery_cg_items:
        renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))

screen cg_gallery():
    tag menu
    use game_menu(_("Галерея"), scroll="viewport"):
        hbox:
            grid gal_cols gal_rows:
                spacing 35
                $ i = 0
                $ next_cg_page = cg_page + 1
                if next_cg_page > int(len(gallery_cg_items)/gal_cells):
                    $ next_cg_page = 0
                for gal_item in gallery_cg_items:
                    $ i += 1
                    if i <= (cg_page+1)*gal_cells and i>cg_page*gal_cells:
                        add g_cg.make_button(gal_item + " butt", gal_item + " butt", im.Scale("gallocked.png", thumbnail_x, thumbnail_y), xalign=0.5, yalign=0.5, idle_border=None, background=None, bottom_margin=0)
                for j in range(i, (cg_page+1)*gal_cells): #we need this to fully fill the grid
                    null
And to unlock the item, in-game I tried to use this:

Code: Select all

$ g_cg.unlock("bg sc01")
But when I return to gallery after I should have unlocked it, it's still locked.

Is there a way to unlock items from the gallery manually, by not showing them to the player?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2397
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Manually unlocking gallery item

#2 Post by Ocelot »

use .condition() instead of .unlock() when setting up your gallery screen.
.unlock() expects name of the image which should be seen to unlock this gallery item.
.condition() expects expression which must be evaluated to True to unlock gallery item.

https://www.renpy.org/doc/html/rooms.html#image-gallery
< < insert Rick Cook quote here > >

GoldenMagician
Newbie
Posts: 19
Joined: Mon Mar 19, 2018 12:44 pm
Contact:

Re: Manually unlocking gallery item

#3 Post by GoldenMagician »

Ocelot wrote: Thu Jul 15, 2021 1:54 pm use .condition() instead of .unlock() when setting up your gallery screen.
.unlock() expects name of the image which should be seen to unlock this gallery item.
.condition() expects expression which must be evaluated to True to unlock gallery item.

https://www.renpy.org/doc/html/rooms.html#image-gallery
Thank you. I will check this out.

Post Reply

Who is online

Users browsing this forum: Google [Bot]