[SOLVED] Toggling two preferences at once with textbuttons

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
Ana
Regular
Posts: 61
Joined: Sun Oct 12, 2014 5:56 pm
Contact:

[SOLVED] Toggling two preferences at once with textbuttons

#1 Post by Ana »

Hello, I have an issue where I want to move the textbox window slightly to the side depending on if the side images are on or off. I was able to manage making it three separate buttons, but I would like to combine these somehow where if the side images are toggled on, the window is "offsettotheside" and if the side images are toggled off, the window is "centeredinthemiddle".

Here is my current code:

Code: Select all

vbox:
	textbutton _("Show Side Images") action [ToggleField(persistent, 'side_images'), SelectedIf(persistent.side_images)]
vbox:
	style_group "pref"
	label _("Side Images Window")
	textbutton _("Window is centred in the middle") action StylePreference("window", "centeredinmiddle")
	textbutton _("Window is offset to the side") action StylePreference("window", "offsettotheside")
Last edited by Ana on Sun May 15, 2022 4:59 pm, edited 1 time in total.

User avatar
m_from_space
Miko-Class Veteran
Posts: 996
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Toggling two preferences at once

#2 Post by m_from_space »

I read your text many times and still don't quite understand what it is you really want to do. Could you rephrase it please?

You can make a button make multiple things at once by just comma-separating the commands.

Code: Select all

textbutton _("Show Side Images"):
   action ToggleField(...), StylePreference(...), etc.

Ana
Regular
Posts: 61
Joined: Sun Oct 12, 2014 5:56 pm
Contact:

Re: Toggling two preferences at once

#3 Post by Ana »

m_from_space wrote: Tue May 10, 2022 6:51 am I read your text many times and still don't quite understand what it is you really want to do. Could you rephrase it please?

You can make a button make multiple things at once by just comma-separating the commands.

Code: Select all

textbutton _("Show Side Images"):
   action ToggleField(...), StylePreference(...), etc.
Hi, thanks for the reply. The problem is, the ToggleField is a button that sets the side image to on or off through one click, but the other button, the style preference (which moves the textbox either [1] to the center or [2] to the side) has two options and needs two separate buttons right now. I can't think of a way to change between
Image

If I set the StylePreference to the center and side image off/on, the textbox will remain in the center. I want it to go:
- side image on, set the textbox off to the side (top image)
- side image off, set the textbox centered in the middle (bottom image)

Can style preference alternate between 2 separate styles with one command?

Edit: alternatively, I'm following this post here regarding turning side images on/off:
viewtopic.php?t=50213
Is there any way to split the toggle button into two separate buttons: an "on" button and an "off" button?

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

Re: Toggling two preferences at once

#4 Post by Ocelot »

You can make a function which does what you want:

Code: Select all

init python:
    def set_window_style():
        if persistent.side_images:
            renpy.set_style_preference("window", "centeredinmiddle")
        else:
            renpy.set_style_preference("window", "offsettotheside")

# . . .
textbutton _("Show Side Images") selected persistent.side_images action [ToggleField(persistent, 'side_images'), Function(set_window_style)]
Or, if you wish, you can use SetField action instead of ToggleField
< < insert Rick Cook quote here > >

Ana
Regular
Posts: 61
Joined: Sun Oct 12, 2014 5:56 pm
Contact:

Re: Toggling two preferences at once

#5 Post by Ana »

Ocelot wrote: Sun May 15, 2022 4:35 pm You can make a function which does what you want:

Code: Select all

init python:
    def set_window_style():
        if persistent.side_images:
            renpy.set_style_preference("window", "centeredinmiddle")
        else:
            renpy.set_style_preference("window", "offsettotheside")

# . . .
textbutton _("Show Side Images") selected persistent.side_images action [ToggleField(persistent, 'side_images'), Function(set_window_style)]
Or, if you wish, you can use SetField action instead of ToggleField
It works perfectly!! Thank you so much!

Post Reply

Who is online

Users browsing this forum: No registered users