Changing the opacity of the Dialogue box with a Slider

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
Yuvan raj
Regular
Posts: 35
Joined: Wed Feb 17, 2021 11:24 am
Contact:

Changing the opacity of the Dialogue box with a Slider

#1 Post by Yuvan raj » Mon Feb 22, 2021 4:29 pm

Hello, Guys! I'm a renpy noob and I'm working on changing the textbox with the help of a slider in the preference screen. I saw a code for it in a blog and copied it and pasted it. And now I can see a slider in the preference screen but when I move the thumb the opacity is not changing.

This code anywhere on the option.rpy

define persistent.dialogueBoxOpacity = 1.0

This code on the preference screen

label _("Dialogue box opacity")
bar value FieldValue(persistent, "dialogueBoxOpacity", range=1.0, style="slider")

And finally, this code under the say screen

window background Transform(Frame("gui/textbox.png",xalign=0.5, yalign=1.0), alpha=persistent.dialogueBoxOpacity)

This is the blog from where I got this code and anyone new can visit this and copy the code and hopefully the answers here also make this code work. https://www.emolgatorium.com/blog/how-d ... -in-renpy/

Thank you!

cheonbyeol
Regular
Posts: 37
Joined: Thu Feb 04, 2021 9:04 am
Contact:

Re: Changing the opacity of the Dialogue box with a Slider

#2 Post by cheonbyeol » Mon Feb 22, 2021 4:34 pm

My first guess is that you define the variable rather than defaulting it, so Ren'Py is not updating it

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Changing the opacity of the Dialogue box with a Slider

#3 Post by zmook » Mon Feb 22, 2021 5:23 pm

That looks like it should work. To try to see why it's not, set

Code: Select all

    define config.developer = True
then restart your game and press shift-O to open the console.
enter

Code: Select all

> persistent.dialogueBoxOpacity
and see if the value is getting changed by your bar slider.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Changing the opacity of the Dialogue box with a Slider

#4 Post by zmook » Mon Feb 22, 2021 5:39 pm

Your error does appear to be using `define` instead of `default` to declare your variable. I'm a little surprised, since I was under the impression that renpy didn't actually enforce that 'defined' variables could not be changed.

Is there something in renpy.store that does in fact mark 'defined' variable as constant? I can't find any real documentation of how renpy.store works.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: Changing the opacity of the Dialogue box with a Slider

#5 Post by hell_oh_world » Mon Feb 22, 2021 6:31 pm

Code: Select all

background Transform(Frame("gui/textbox.png",xalign=0.5, yalign=1.0), alpha=persistent.dialogueBoxOpacity)
if this is set in the `style window` inside `screens.rpy` then it won't since this only gets executed once (when the style is being defined during init).
you have to do it inside the `say` screen in `screens.rpy` not in the style.
so find that screen and in the `window` with `id 'window'`, add `background Transform(Frame("gui/textbox.png",xalign=0.5, yalign=1.0), alpha=persistent.dialogueBoxOpacity)`.
Also, its a common practice to use `default` statements on `persistent` variables.

Yuvan raj
Regular
Posts: 35
Joined: Wed Feb 17, 2021 11:24 am
Contact:

Re: Changing the opacity of the Dialogue box with a Slider

#6 Post by Yuvan raj » Tue Feb 23, 2021 12:28 am

zmook wrote:
Mon Feb 22, 2021 5:23 pm
That looks like it should work. To try to see why it's not, set

Code: Select all

    define config.developer = True
then restart your game and press shift-O to open the console.
enter

Code: Select all

> persistent.dialogueBoxOpacity
and see if the value is getting changed by your bar slider.
Thank you for the reply. I just found out that the opacity does changes but the lowest opacity didn't make it invisible.
Last edited by Yuvan raj on Tue Feb 23, 2021 3:46 pm, edited 1 time in total.

Yuvan raj
Regular
Posts: 35
Joined: Wed Feb 17, 2021 11:24 am
Contact:

Re: Changing the opacity of the Dialogue box with a Slider

#7 Post by Yuvan raj » Tue Feb 23, 2021 12:31 am

hell_oh_world wrote:
Mon Feb 22, 2021 6:31 pm

Code: Select all

background Transform(Frame("gui/textbox.png",xalign=0.5, yalign=1.0), alpha=persistent.dialogueBoxOpacity)
if this is set in the `style window` inside `screens.rpy` then it won't since this only gets executed once (when the style is being defined during init).
you have to do it inside the `say` screen in `screens.rpy` not in the style.
so find that screen and in the `window` with `id 'window'`, add `background Transform(Frame("gui/textbox.png",xalign=0.5, yalign=1.0), alpha=persistent.dialogueBoxOpacity)`.
Also, its a common practice to use `default` statements on `persistent` variables.
Thank you for replying! It was already working, and I didn't notice it as the lowest value didn't make it fully transparent but just a little bit.
Last edited by Yuvan raj on Tue Feb 23, 2021 3:45 pm, edited 1 time in total.

Yuvan raj
Regular
Posts: 35
Joined: Wed Feb 17, 2021 11:24 am
Contact:

Re: Changing the opacity of the Dialogue box with a Slider

#8 Post by Yuvan raj » Tue Feb 23, 2021 12:33 am

cheonbyeol wrote:
Mon Feb 22, 2021 4:34 pm
My first guess is that you define the variable rather than defaulting it, so Ren'Py is not updating it
Thank you so much for the reply! Both works I but it won't become fully transparent so I didn't notice it before.
Last edited by Yuvan raj on Tue Feb 23, 2021 3:43 pm, edited 1 time in total.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: Changing the opacity of the Dialogue box with a Slider

#9 Post by hell_oh_world » Tue Feb 23, 2021 2:40 am

for the `alpha` property `0.0` means transparent, while `1.0` is opaque. So the `alpha` actually only takes values between `0.0` and `1.0`.
Also, no need to spam the same message to everyone who answered your question.

Post Reply

Who is online

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