Ren'Py Is there an equivilent of ToggleVariable for images?

MissFortune

I Was Once, Possibly, Maybe, Perhaps… A Harem King
Respected User
Game Developer
Aug 17, 2019
6,789
10,501
872
I'm trying to add a toggle for a thin, decorative frame around the VN/renders. I already have an on/off imagebutton/switch ready. Just can't seem to find/figure out the code that would be necessary.

I have the basic ToggleVariable set up:

Python:
imagebutton:
            xpos 930
            ypos 240
            idle "images/menu/ui/eatui/off.png"
            hover "images/menu/ui/eatui/off.png"
            selected_idle "images/menu/ui/eatui/on.png"
            selected_hover "images/menu/ui/eatui/on.png"
            focus_mask True
            action ToggleVariable("screenframevar", True, False), Play("sound", "music/confirm.wav")
            selected (screenframevar)
which looks something like this:

screenshot0001.png

But the On/Off don't seem to register at all, which is why I'm asking. Feels like I'm missing something fairly obvious.
 

GetOutOfMyLab

Conversation Conqueror
Modder
Aug 13, 2021
7,980
23,239
832
What's not happening as you expected? The On/Off button isn't toggling?
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,656
2,347
462
idle and hover should accept a displayable as it's parameter.

That being the case, you should then be able to use to pick which version of the image to display.

Something like :-

Python:
image on_off_idle = ConditionSwitch(
    "screenframevar = True", "images/menu/ui/eatui/off_idle.png",
    "True", "images/menu/ui/eatui/on.png_idle" )
image on_off_hover = ConditionSwitch(
    "screenframevar = True", "images/menu/ui/eatui/off_hover.png",
    "True", "images/menu/ui/eatui/on_hover.png" )

# --- elsewhere in your code...

imagebutton:
    xpos 930
    ypos 240
    idle on_off_idle
    hover on_off_hover
    action { ToggleVariable("screenframevar", True, False), Play("sound", "music/confirm.wav") }
btw... you don't need idle AND hover if the hover image is the same as the idle image.

Maybe (I'm unable to test code at the moment) - so you may need to tweak it a bit.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
12,723
20,875
1,026
I'm trying to add a toggle for a thin, decorative frame around the VN/renders. I already have an on/off imagebutton/switch ready. Just can't seem to find/figure out the code that would be necessary.
Because you are looking in the wrong direction.

One way could be:
Python:
screen whatever():

        imagebutton:
            xpos 930
            ypos 240
            if screenframevar:
                idle "images/menu/ui/eatui/on.png"
                hover "images/menu/ui/eatui/on.png"
            else:
                idle "images/menu/ui/eatui/off.png"
                hover "images/menu/ui/eatui/off.png"
            action ToggleVariable("screenframevar", True, False), Play("sound", "music/confirm.wav")
            selected (screenframevar)
But I show it only as example, and only because it can come handy for other situation.


The effective way to do it is to rely on a radically different approach, textbutton.
You use the textbutton itself to display the label, and rely on the " " property to display the button accordingly to the right . A bit of styling (offset and all), and it's done.

I can't test right now, but it's something that would looks like this:
Python:
style myRadio is button:
    background "images/menu/ui/eatui/off.png"
    selected_background "images/menu/ui/eatui/on.png"

style myRadio_text is button_text:
    yoffset -5

screen whatever():
        textbutton "NTR":
            xpos 930
            ypos 240
            style "myRadio"
            action ToggleVariable("screenframevar", True, False), Play("sound", "music/confirm.wav")
            selected (screenframevar)
 
  • Like
Reactions: 79flavors

UncleNanard

I am to music what Kanye West is to AVN.
Game Developer
Jul 1, 2017
1,880
1,825
418
Hello, I'm embarrassed to post here. I don't have the level of expertise of Anne and 79, and maybe I didn't fully understand the problem, but why don't you use an auto ImageButton?

Python:
imagebutton auto "images/menu/ui/eatui/off_%s.png" action ToggleVariable("screenframevar", True, False) Play("sound", "music/confirm.wav")
Use these names for your images:

off_hover
off_idle
off_selected_hover
off_selected_idle

I might be saying something silly, so please don't pay much attention to my message... I'll just go quickly. :p
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
12,723
20,875
1,026
I might be saying something silly, so please don't pay much attention to my message... I'll just go quickly. :p
It isn't silly, at the opposite, and I don't see a reason why it wouldn't works.