[SOLVED]Toggle checkbox imagebutton?

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
eath
Newbie
Posts: 10
Joined: Tue Jul 14, 2020 11:52 am
Contact:

[SOLVED]Toggle checkbox imagebutton?

#1 Post by eath »

This should be a very simple thing, but I'm brand new to Ren'py and can't find it…

Here's what I want to do in pseudocode:

Code: Select all

show current imagebutton state (on or off)

imagebutton:
    if x==True: imagebutton's image = "on.jpg"
    if x==False: imagebutton's image = "off.jpg"
    onclick: toggle x

replace/show current imagebutton state (on or off)
I feel like I'm ignorant of a very basic checkbox command that takes care of this in a simple way. I've spent hours looking up imagebuttons and my code just keeps getting more and more convoluted. Help! please!

If it matters, this will be a layer on top of another image.

Thanks!
Last edited by eath on Mon Jul 20, 2020 6:50 pm, edited 1 time in total.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Toggle checkbox imagebutton?

#2 Post by Imperf3kt »

You can use the selected_hover and selected_idle states for this
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

eath
Newbie
Posts: 10
Joined: Tue Jul 14, 2020 11:52 am
Contact:

Re: Toggle checkbox imagebutton?

#3 Post by eath »

Well, this seems to do what I want it to do... but I am still willing to learn a better way of doing things!

Code: Select all

default buttonvalue = False

screen alternatebuttonswitch():
    modal True
    imagebutton:
        focus_mask True
        if buttonvalue == True: 
            idle "on.png"
        else:
            idle "off.png"
        action [ToggleVariable("buttonvalue", True, False)]

show screen alternatebuttonswitch
If anyone can tell me how to add a quick "button shifted downwards" image during a tap, I'd be grateful!

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Toggle checkbox imagebutton?

#4 Post by Imperf3kt »

selected_idle and selected_hover do what you want.

You can use them like this.

Code: Select all

screen alternatebuttonswitch():
    modal True
    imagebutton:
        focus_mask True
        idle "off.png"
        hover "off.png"
        selected_idle "on.png"
        selected_hover "on.png"
        action NullAction() 

More states and info here
https://www.renpy.org/doc/html/style_pr ... y-prefixes
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

eath
Newbie
Posts: 10
Joined: Tue Jul 14, 2020 11:52 am
Contact:

Re: Toggle checkbox imagebutton?

#5 Post by eath »

Thanks, all! That works great!

Post Reply

Who is online

Users browsing this forum: No registered users