[RESOLVED] How to create new slider variable in preferences screen?

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
Jovid Jomith
Newbie
Posts: 21
Joined: Tue Jun 18, 2019 11:10 am
Contact:

[RESOLVED] How to create new slider variable in preferences screen?

#1 Post by Jovid Jomith »

Hello. I'd like to create a slider for a variable I've called persistent.outlinealpha.
It's a float that takes an argument from 0.0 to 1.0 (defaulting at 0.8).

I would like to be able to mimic how the audio sliders currently are, but all I can see of their code is:

Code: Select all

            vbox:

                if config.has_music:
                    label _("Music Volume")

                    hbox:
                        bar value Preference("music volume")
I can't seem to find their initial definitions in the options.rpy script or anywhere else to be able to use when creating my own.

Any help would be greatly appreciated!
Last edited by Jovid Jomith on Tue Jul 18, 2023 10:18 am, edited 2 times in total.

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: How to create new slider variable in preferences screen?

#2 Post by enaielei »

VariableValue

Code: Select all

bar value VariableValue("persistent.outlinealpha", 1.0)

Jovid Jomith
Newbie
Posts: 21
Joined: Tue Jun 18, 2019 11:10 am
Contact:

Re: How to create new slider variable in preferences screen?

#3 Post by Jovid Jomith »

enaielei wrote: Wed Jul 12, 2023 10:01 pm VariableValue

Code: Select all

bar value VariableValue("persistent.outlinealpha", 1.0)
This works!! Thank you!
Just one more question: Is there a way to make this match the default look of Music Volume and Sound Volume?

This is how mine appears (if the image sends).
Attachments
Screenshot 2023-07-13 114112.png

Jovid Jomith
Newbie
Posts: 21
Joined: Tue Jun 18, 2019 11:10 am
Contact:

Re: How to create new slider variable in preferences screen?

#4 Post by Jovid Jomith »

enaielei wrote: Wed Jul 12, 2023 10:01 pm VariableValue

Code: Select all

bar value VariableValue("persistent.outlinealpha", 1.0)
Ah, also, the variable, when changed from the slider, does not seem to save upon exiting and reopening the game, even though it should be persistent. Would you have any idea why that could be happening?

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: How to create new slider variable in preferences screen?

#5 Post by enaielei »

Just one more question: Is there a way to make this match the default look of Music Volume and Sound Volume?
There are pre-defined styles just below or above the screen you're currently at. You can use those to copy the style. Or you can just simply put your bar right next to the other bars so that it will also inherit the styles.

Ah, also, the variable, when changed from the slider, does not seem to save upon exiting and reopening the game, even though it should be persistent. Would you have any idea why that could be happening?
How are you using the variable? Take note also that persistent variables only get saved if the game is exited properly (thru the close button or popping the exit confirmation, etc.)

Jovid Jomith
Newbie
Posts: 21
Joined: Tue Jun 18, 2019 11:10 am
Contact:

Re: How to create new slider variable in preferences screen?

#6 Post by Jovid Jomith »

enaielei wrote: Thu Jul 13, 2023 6:18 pm
Just one more question: Is there a way to make this match the default look of Music Volume and Sound Volume?
There are pre-defined styles just below or above the screen you're currently at. You can use those to copy the style. Or you can just simply put your bar right next to the other bars so that it will also inherit the styles.

Ah, also, the variable, when changed from the slider, does not seem to save upon exiting and reopening the game, even though it should be persistent. Would you have any idea why that could be happening?
How are you using the variable? Take note also that persistent variables only get saved if the game is exited properly (thru the close button or popping the exit confirmation, etc.)
It's already next to the other bars, but it's not inheriting the styles for some reason. I would think it's because it uses VariableValue instead of Preference? But with Preference, I couldn't get it to work.

Code: Select all

            vbox:

                if config.has_music:
                    label _("Music Volume")

                    hbox:
                        bar value Preference("music volume")


                if config.has_sound:

                    label _("Sound Volume")

                    hbox:
                        bar value Preference("sound volume")

                        if config.sample_sound:
                            textbutton _("Test") action Play("sound", config.sample_sound)

                if config.has_music or config.has_sound or config.has_voice:
                    null height gui.pref_spacing

                    textbutton _("Mute All"):
                        action Preference("all mute", "toggle")
                        style "mute_all_button"

                label _("Sprite Outlines")
                
                hbox:
                    bar value VariableValue("persistent.outlinealpha", 1.0)
This is how it looks within my preferences screen at the moment.

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: How to create new slider variable in preferences screen?

#7 Post by enaielei »

There are pre-defined styles just below or above the screen you're currently at. You can use those to copy the style.
Move your cursor to the existing bar, then shift + i. You'll see the style that it uses. Now use that style in your bar.

Jovid Jomith
Newbie
Posts: 21
Joined: Tue Jun 18, 2019 11:10 am
Contact:

Re: How to create new slider variable in preferences screen?

#8 Post by Jovid Jomith »

enaielei wrote: Sun Jul 16, 2023 4:47 pm
There are pre-defined styles just below or above the screen you're currently at. You can use those to copy the style.
Move your cursor to the existing bar, then shift + i. You'll see the style that it uses. Now use that style in your bar.
I checked both the existing music slider, and my new slider.
My new slider is classified as "slider_bar" while the default music slider is "slider_slider".
How can I change it to match, within the code?

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: How to create new slider variable in preferences screen?

#9 Post by enaielei »

https://www.renpy.org/doc/html/style.html#using-styles-and-style-inheritance wrote: Each displayable takes a property named style, which applies the said style to the displayable:

Code: Select all

image big hello world = Text("Hello World", style="big")

screen hello_world:
    text "Hello, World" style "big"

Jovid Jomith
Newbie
Posts: 21
Joined: Tue Jun 18, 2019 11:10 am
Contact:

Re: How to create new slider variable in preferences screen?

#10 Post by Jovid Jomith »

enaielei wrote: Sun Jul 16, 2023 6:11 pm
https://www.renpy.org/doc/html/style.html#using-styles-and-style-inheritance wrote: Each displayable takes a property named style, which applies the said style to the displayable:

Code: Select all

image big hello world = Text("Hello World", style="big")

screen hello_world:
    text "Hello, World" style "big"
The music and sfx sliders don't have styles attached to them. And if the entire preferences screen did, shouldn't my bar automatically be adjusted by it?
There must be a way to use Preference() instead of VariableValue(), is there not? I tried doing some research but I couldn't find anything that helped me solve this. I tried attaching different styles to the current slider, tried attaching every style that's currently connected to the preference screen, but it stays the same each time I save and reload the game.

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: How to create new slider variable in preferences screen?

#11 Post by enaielei »

You already know that the existing bars use the style "slider_slider". And I sent the quote explaining how to use styles. So...

Code: Select all

bar value VariableValue(...) style "slider_slider"
Check the style of the bar again using the inspector and see if the style of the bar really changed to "slider_slider". It should be since I tested this on a project myself.

Jovid Jomith
Newbie
Posts: 21
Joined: Tue Jun 18, 2019 11:10 am
Contact:

Re: How to create new slider variable in preferences screen?

#12 Post by Jovid Jomith »

enaielei wrote: Mon Jul 17, 2023 5:33 pm You already know that the existing bars use the style "slider_slider". And I sent the quote explaining how to use styles. So...

Code: Select all

bar value VariableValue(...) style "slider_slider"
Check the style of the bar again using the inspector and see if the style of the bar really changed to "slider_slider". It should be since I tested this on a project myself.
Oh, that's my bad, I was adding a colon and then underneath adding style_prefix "slider_slider". This ended up working then, thank you for that, I really appreciate your help and patience!

Post Reply

Who is online

Users browsing this forum: Google [Bot]