Page 1 of 1

[Error] Gallery always locked

Posted: Fri Feb 19, 2016 9:22 pm
by hiroki2k
Tried to use the gallery that is on the rooms page of the wiki on renpy.org, and it shows, but when it should unlock the scene related to it it doesn't unlock anything. I don't know if I'm doing it wrong, or if I'm really noob with this...

Code: Select all

init python:

    # Step 1. Create the gallery object.
    g = Gallery()

    # Step 2. Add buttons and images to the gallery.

    # A button that contains an image that automatically unlocks.
    g.button("escena1")
    g.condition("persistent.unlock_1")
    g.unlock("cg/momento_divertido.png")

    # This button has multiple images assocated with it. We use unlock_image
    # so we don't have to call both .image and .unlock. We also apply a
    # transform to the first image.
    g.button("escena2")
    g.unlock_image("momento")

    # This button has a condition associated with it, allowing code
    # to choose which images unlock.
    g.button("escena3")
    g.unlock_image("escena3")

    g.button("escena4")
    g.unlock_image("escena4")

    # The last image in this button has an condition associated with it,
    # so it will only unlock if the user gets both endings.
    g.button("final1")
    g.unlock_image("final2")
    
    g.button("final2")
    g.unlock_image("final2")

    # The final two buttons contain images that show multiple pictures
    # at the same time. This can be used to compose character art onto
    # a background.
    g.button("final3")
    g.unlock_image("final3")

    g.button("final4")
    g.unlock_image("final4")

    # The transition used when switching images.
    g.transition = dissolve

# Step 3. The gallery screen we use.
screen gallery:

    # Ensure this replaces the main menu.
    tag menu

    # The background.
    add "sys/fondo.png"

    # A grid of buttons.
    grid 3 3:

        xfill True
        yfill True

        # Call make_button to show a particular button.
        add g.make_button("escena1", "sys/gallocked.png", xalign=0.5, yalign=0.5)
        add g.make_button("escena2", "sys/gallocked.png", xalign=0.5, yalign=0.5)
        add g.make_button("escena3", "sys/gallocked.png", xalign=0.5, yalign=0.5)
        add g.make_button("escena4", "sys/gallocked.png", xalign=0.5, yalign=0.5)
        add g.make_button("final1", "sys/gallocked.png", xalign=0.5, yalign=0.5)
        add g.make_button("final2", "sys/gallocked.png", xalign=0.5, yalign=0.5)
        add g.make_button("final3", "sys/gallocked.png", xalign=0.5, yalign=0.5)
        add g.make_button("final4", "sys/gallocked.png", xalign=0.5, yalign=0.5)        


        # The screen is responsible for returning to the main menu. It could also
        # navigate to other gallery screens.
        textbutton "Return" action Return() xalign 0.5 yalign 0.5

Re: [Error] Gallery always locked

Posted: Tue Feb 23, 2016 11:11 am
by Steamgirl
Hmmm where do you set $ persistent.unlock_1 = True in your script?

Re: [Error] Gallery always locked

Posted: Tue Feb 23, 2016 4:36 pm
by hiroki2k
Steamgirl wrote:Hmmm where do you set $ persistent.unlock_1 = True in your script?
Exactly after the related image is shown ingame. The thinng is that I don't know even if my game sets the variable as true or false, as it doesn't appear on the developer's menu when I try to view variables.

Re: [Error] Gallery always locked

Posted: Tue Feb 23, 2016 5:04 pm
by Steamgirl
You could try adding "global persistent.unlock_1" to the python script, in case it's not recognising it as a global variable.

So...

Code: Select all

init python:

    # Make this a global variable
    global persistent.unlock_1

    # Step 1. Create the gallery object.
    g = Gallery()
Also, you can add a line to your gallery screen to see it's true or false?

Code: Select all

        add g.make_button("final2", "sys/gallocked.png", xalign=0.5, yalign=0.5)
        add g.make_button("final3", "sys/gallocked.png", xalign=0.5, yalign=0.5)
        add g.make_button("final4", "sys/gallocked.png", xalign=0.5, yalign=0.5) 

    if persistent.unlock_1:
        text "Gallery variable is unlocked! :)" xalign 0.5 yalign 0.1
    else:
        text "Gallery variable is not unlocked. :(" xalign 0.5 yalign 0.1

        # The screen is responsible for returning to the main menu. It could also
        # navigate to other gallery screens.
        textbutton "Return" action Return() xalign 0.5 yalign 0.5

Re: [Error] Gallery always locked

Posted: Tue Feb 23, 2016 5:13 pm
by hiroki2k
Solved. Thanks for the help ^^

Re: [Error] Gallery always locked

Posted: Tue Feb 23, 2016 6:10 pm
by Steamgirl
Phew! If only it was always this easy! Glad to have been of assistance. :)

Re: [Error] Gallery always locked

Posted: Tue Feb 23, 2016 8:12 pm
by hiroki2k
Steamgirl wrote:Phew! If only it was always this easy! Glad to have been of assistance. :)
The problem was really simple:

This wasn't doing anything:

Code: Select all

    g.button("escena1")
    g.condition("persistent.unlock_1")
    g.unlock("cg/momento_divertido.png")
But, this one:

Code: Select all

    g.button("escena1")
    g.condition("persistent.unlock_1")
    g.image("cg/momento_divertido.png")
Did the trick (I even tried using the definitions withing the game itself for the image, but putting the image route works anyway so... If it works, doun't touch it IMO