Page 1 of 1

Replacing Images in Gallery

Posted: Mon Oct 26, 2020 9:41 pm
by krt_org
I'm working on a gallery for my vn, specifically, I am making a gallery for profiles for the characters in my game. I used the code from this thread https://lemmasoft.renai.us/ ... hp?t=46976 as a base for gallery. It works fine to get the pictures where I want them, but I'm unsure how to solve my current problem.

I want to switch out the profiles on the characters' birthdays. I guess I could create a new spot for the new profile for each year, but it'd be redundant to have the old profile still visible or lock it and have a bunch of locked images in front of the new ones.

Can someone please direct me so I can figure out how I would write the code so that the right profile is displayed in the right spot at the right time?

Code: Select all

init python:

    gl = Gallery()

    #The image I have programmed to display
    gl.button("t1")
    gl.condition("persistent.t12")
    gl.image("t1.png")
    
    #The image I want to display later in the same spot
    #I'm thinking I probably want the new button to also be "t1" and not "t3", but 
    # for the sake of dividing them while writing the code, I did this.
    gl.button("t3")
    gl.condition("persistent.t34")
    gl.image("t3.png")

   screen gallery2:

    tag menu

    add "/gui/game_menu.png"

    vpgrid:

        cols 10
        rows 2
        spacing 5
        draggable True

        scrollbars "horizontal" yalign -0.5

        xfill True
        yfill False
        
        #This is where I have the button made for persistent.t12
        add gl.make_button("t1","t1.png", locked = "/gui/lock.png", xalign=0.5, yalign=0.5)    
        
   textbutton "Return" action Return() xalign 0.9 yalign 1.0
    
I thought obviously using if-else clauses could totally make this thing work, but you are unable to do logic in python files...?
I don't remember what the error was, but it didn't work when I did it right in the add gl.make_button(...) or when I did it after the return button was added at the end of the code. I searched around the vpgrid documentation and just the general renpy documentation, but I couldn't find anything that I could get to work. I'm using a vpgrid, but I could not get the normal grid to understand what dimensions I was using.

If I can't directly replace the picture based on the condition, I would hope I would be able to delete the old profile out of the grid when it's not needed and have the new profile just at the end of the list. I just don't even know if this is possible right now.

Re: Replacing Images in Gallery

Posted: Fri Oct 30, 2020 7:11 am
by gas
Quick reply: yes, you can state a different picture based on conditionals.
The .condition() function work on the previous element you added, so you can do:

Code: Select all

gl.image("t1.png")
gl.condition("birthdate == 0")
gl.image("t2.png")
gl.condition("birthdate == 1")
that's equivalent to tell "show picture 1 if variable == 0, or show picture 2 if variable == 1"

Now, the thing become complex if you want to change the button pic, as you need an if in the gl.make button sequence that somehow replicate the above logic:

Code: Select all

if birthdate == 1:
    add gl.make_button("t1","t1.png", locked = "/gui/lock.png", xalign=0.5, yalign=0.5)
else:
    add gl.make_button("t1","t2.png", locked = "/gui/lock.png", xalign=0.5, yalign=0.5)
Pleease notice that you always reference t1 button in the make_button.

Re: Replacing Images in Gallery

Posted: Sun Nov 01, 2020 8:10 pm
by krt_org
This seems like it would definitely work in theory. Oddly, when I tried it, the button I added the logic clauses to just stopped showing up in the gallery altogether. I decided to not switch the profiles out after spending a few hours messing around with it...I appreciate the help, though. I think this looks like it should work, I'm just not very good at coding, I think.

Re: Replacing Images in Gallery

Posted: Sun Nov 01, 2020 8:47 pm
by Imperf3kt
It would probably be better to use a dynamic image such as ConditionSwitch instead of two different buttons.
https://www.renpy.org/doc/html/displaya ... tionSwitch

You may need predict_all set to True.

Re: Replacing Images in Gallery

Posted: Mon Nov 02, 2020 1:49 pm
by gas
It's probably just a matter of persistent use. You should check the same persistent not two different persistents, or maybe you're creating a "false and false" situation.
I'm sure it does work, I've already did it.
Post your code here and let's see to solve it, it's sad to remove a feature we can implement!

@ Imperf3xt: the user here doesn't want just to show a different button image, but also a different button content.