[solved] Image Gallery problems

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
Kaen
Regular
Posts: 148
Joined: Tue Oct 16, 2012 10:49 pm
Contact:

[solved] Image Gallery problems

#1 Post by Kaen »

Hello everyone.

I'm trying to use image gallery following this tutorial but I need help on some things.

The code doesn't give me any erros, but I don't know how I can unlock a image to see it on the gallery. I used both gallery.unlock and gallery.unlock_image but neither helped me.

I read that a image is unlocked after the player sees it, so I added the images on the game via character and background but even after I see them I can't unlock them on the gallery.

The following code is on script.rpy.

Code: Select all

# Declare images below this line, using the image statement.
image bg01_00 = "image/gallery/1-0.png"
image bg01_01 = "image/gallery/1-1.png"
image teste 01 = "image/gallery/1-1.png"

# Declare characters used by this game.
define e = Character('Eileen', color="#c8ffc8")

init python:
    # Step 1. Create the gallery object.
    g = Gallery()
    
    # The transition used when switching images.
    g.transition = dissolve
    
    # An image used as the background of the various gallery pages.
    g.background = "image/gallery/gallery_background.jpg"
    
    # The image used for locked buttons.
    g.locked_button = "image/gallery/gallerybutton_locked.png"
    
    # The background of a locked image. 
    g.locked_background = "image/gallery/gallery_background.jpg"    

    # Step 2. Add buttons and images to the gallery.
    # A button that contains an image that automatically unlocks.
    g.button("1-0")    
    g.image("image/gallery/1-1.png")
    g.unlock("image/gallery/1-1.png")

    # This button has multiple images assocated with it. 
    # We use unlock_image so we don't have to call both .image and .unlock.
    g.button("2-0")
    g.unlock_image("image/gallery/2-1.png")
    
    g.button("3-0")
    g.unlock_image("image/gallery/3-1.png", "image/gallery/3-2.png")
    
    g.button("4-0")
    g.unlock_image("image/gallery/4-1.png", "image/gallery/4-2.png")
    
    g.button("5-0")
    g.unlock_image("image/gallery/5-1.png", "image/gallery/5-2.png")
    
# Step 3. The gallery screen we use.
screen gallery:

    # Ensure this replaces the main menu.
    tag menu

    # The background.
    add "image/gallery/gallery_background.jpg"

    # A grid of buttons.
    grid 3 3:

        xfill True
        yfill True

        # Call make_button to show a particular button.
        add g.make_button("1-0", "image/gallery/1-0.png", xalign=0.5, yalign=0.5)
        add g.make_button("1-0", "image/gallery/1-1.png", xalign=0.5, yalign=0.5)
        add g.make_button("2-0", "image/gallery/2-0.png", xalign=0.5, yalign=0.5)
        
        add g.make_button("3-0", "image/gallery/3-0.png", xalign=0.5, yalign=0.5)
        add g.make_button("4-0", "image/gallery/4-0.png", xalign=0.5, yalign=0.5)
        add g.make_button("5-0", "image/gallery/5-0.png", xalign=0.5, yalign=0.5)
        
        null
        null

        # 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    

# The game starts here.
label start:    
    scene bg01_00
    show teste 01 at left
    e "You've created a new Ren'Py game."

    scene bg01_01
    e "Once you add a story, pictures, and music, you can release it to the world!"

    return
And this code is on screens.rpy to add the gallery button on the main menu.

Code: Select all

textbutton "Gallery" action ShowMenu("gallery")
Can anyone help me pelase?
Last edited by Kaen on Sat Jul 12, 2014 10:12 am, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Image Gallery problems

#2 Post by PyTom »

The problem here is that g.unlock_image expects an image name, like "eileen happy", rather than the image filename. Ren'Py tracks the image names, not the filenames, so that's what you have to unlock as.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Kaen
Regular
Posts: 148
Joined: Tue Oct 16, 2012 10:49 pm
Contact:

Re: Image Gallery problems

#3 Post by Kaen »

Thank you sir, that was very helpful.

If it's possible I'd like to understand how can I navigate to another gallery screen. I know it's related to the code above but I can't quite figure it out.

Code: Select all

# 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

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]