[Error] Gallery always locked

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
hiroki2k
Newbie
Posts: 18
Joined: Mon Feb 15, 2016 12:23 pm
Projects: Kaichō Wa Gēmā Desu!
Organization: Fuji Doujin Soft
Deviantart: othork
Skype: hiroki2k
Contact:

[Error] Gallery always locked

#1 Post 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

User avatar
Steamgirl
Veteran
Posts: 322
Joined: Sat Jul 28, 2012 4:39 am
Completed: My Cup of Coffee, Queen at Arms (co-wrote a battle scene)
Projects: Stranded Hearts, Emma: A Lady's Maid
Deviantart: steamgirlgame
Contact:

Re: [Error] Gallery always locked

#2 Post by Steamgirl »

Hmmm where do you set $ persistent.unlock_1 = True in your script?

hiroki2k
Newbie
Posts: 18
Joined: Mon Feb 15, 2016 12:23 pm
Projects: Kaichō Wa Gēmā Desu!
Organization: Fuji Doujin Soft
Deviantart: othork
Skype: hiroki2k
Contact:

Re: [Error] Gallery always locked

#3 Post 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.

User avatar
Steamgirl
Veteran
Posts: 322
Joined: Sat Jul 28, 2012 4:39 am
Completed: My Cup of Coffee, Queen at Arms (co-wrote a battle scene)
Projects: Stranded Hearts, Emma: A Lady's Maid
Deviantart: steamgirlgame
Contact:

Re: [Error] Gallery always locked

#4 Post 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

hiroki2k
Newbie
Posts: 18
Joined: Mon Feb 15, 2016 12:23 pm
Projects: Kaichō Wa Gēmā Desu!
Organization: Fuji Doujin Soft
Deviantart: othork
Skype: hiroki2k
Contact:

Re: [Error] Gallery always locked

#5 Post by hiroki2k »

Solved. Thanks for the help ^^

User avatar
Steamgirl
Veteran
Posts: 322
Joined: Sat Jul 28, 2012 4:39 am
Completed: My Cup of Coffee, Queen at Arms (co-wrote a battle scene)
Projects: Stranded Hearts, Emma: A Lady's Maid
Deviantart: steamgirlgame
Contact:

Re: [Error] Gallery always locked

#6 Post by Steamgirl »

Phew! If only it was always this easy! Glad to have been of assistance. :)

hiroki2k
Newbie
Posts: 18
Joined: Mon Feb 15, 2016 12:23 pm
Projects: Kaichō Wa Gēmā Desu!
Organization: Fuji Doujin Soft
Deviantart: othork
Skype: hiroki2k
Contact:

Re: [Error] Gallery always locked

#7 Post 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

Post Reply

Who is online

Users browsing this forum: Bing [Bot]