Toggle changes of scene automatically (ConditionSwitch, Persistent Data)

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
chellophane
Newbie
Posts: 15
Joined: Fri Dec 06, 2019 11:24 pm
Contact:

Toggle changes of scene automatically (ConditionSwitch, Persistent Data)

#1 Post by chellophane »

Hello! I am currently working on a game that features a censor for H-scenes but I am having a hard time figuring how to make the images change on their own.

In my settings screen, the toggle is defined this way using persistent data and it works as expected. This is the vbox and image buttons containing said settings in my preference screen.

Code: Select all

                vbox:
                    style_prefix "radio"
                    label _("GRAPHICS")
                    imagebutton:
                        auto "gui/button/radio_%s_background.png"
                        foreground Text(_("Enable nudity"), style="custom_btn_txt")
                        hover_foreground Text(_("Enable nudity"), style="custom_btn_txt_hover")
                        action SetField(persistent, "h_content", 1)

                    imagebutton:
                        auto "gui/button/radio_%s_background.png"
                        foreground Text(_("Disable nudity"), style="custom_btn_txt")
                        hover_foreground Text(_("Disable nudity"), style="custom_btn_txt_hover")
                        action SetField(persistent, "h_content", 0)
I am using a ConditionSwitch block to define my image like this and it works as expected:

Code: Select all

    image bed = ConditionSwitch (
        "h_content == 0","bed_censored.png",
        "h_content == 1","bed.png",
        "True", "blank.png"                      
        )

Also, in my script, before the said scene shows, I use the following statement to make sure the value of h_content is correct:

Code: Select all

    # script text here  

    $ h_content = persistent.h_content
    scene bed with dissolve 

    # more script text here 
Technically, this works, as the image updates when i rollback and go over the line of script again. However, I wish for the images to switch as the user clicks on the button on the settings menu. I tried adding the renpy.restart_interaction function to the actions of the return image button of my navigation screen as an attempt to maybe refresh the screen, but i wasn't successful.

Am I going on about this the wrong way for the images to switch automatically? I would really appreciate if anyone has an idea on how to solve this, that would really help - Thank you very much !!
i was redredswap!!!!!!

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Toggle changes of scene automatically (ConditionSwitch, Persistent Data)

#2 Post by enaielei »

How are you using the `renpy.restart_interaction`? it should be used using the `Function` action. Also, if I'm not mistaken, I think you can directly do in the `ConditionSwitch` conditions such as `persistent.h_content == ...`, if not then you can directly set the value of `h_content` itself in the button.

Code: Select all

imagebutton:
    ...
    action (SetField(persistent, "h_content", 0), SetVariable("h_content", persistent.h_content), Function(renpy.restart_interaction))

chellophane
Newbie
Posts: 15
Joined: Fri Dec 06, 2019 11:24 pm
Contact:

Re: Toggle changes of scene automatically (ConditionSwitch, Persistent Data)

#3 Post by chellophane »

enaielei wrote: Sun Oct 24, 2021 12:12 pm How are you using the `renpy.restart_interaction`? it should be used using the `Function` action. Also, if I'm not mistaken, I think you can directly do in the `ConditionSwitch` conditions such as `persistent.h_content == ...`, if not then you can directly set the value of `h_content` itself in the button.

Code: Select all

imagebutton:
    ...
    action (SetField(persistent, "h_content", 0), SetVariable("h_content", persistent.h_content), Function(renpy.restart_interaction))
I thought to use renpy.restart_interaction as an attempt to maybe refresh the screen and have the images switch from censored to uncensored. Also, using the line of code you provided is more effective coding! Unfortunately, it yields the same result :(
i was redredswap!!!!!!

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2426
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Toggle changes of scene automatically (ConditionSwitch, Persistent Data)

#4 Post by Ocelot »

enaielei wrote: Sun Oct 24, 2021 12:12 pm

Code: Select all

imagebutton:
    ...
    action (SetField(persistent, "h_content", 0), SetVariable("h_content", persistent.h_content), Function(renpy.restart_interaction))
That SetVariable should read SetVariable("h_content", 0), because otherwise it will set h_content to the value persistent.h_content had when the screen was last updated.
< < insert Rick Cook quote here > >

Post Reply

Who is online

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