How to add a new preference config to settings 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
User avatar
thirstyoctopus
Regular
Posts: 60
Joined: Mon Aug 27, 2018 12:04 pm
Projects: Romance Visual Novel story
Organization: Thirsty Octopus
Contact:

How to add a new preference config to settings screen

#1 Post by thirstyoctopus » Sun Nov 10, 2019 12:14 pm

Hello, I have some DLC for my game that I want to release but I need a toggle / radio option in the Settings in order to enable what this DLC adds. In this case, it allows the user to enable it to see the adult mode sprites in the game, and disable it if they don't.

After some research it seems that all I need to do is add the button into the preferences screen in screens.rpy so I did this:

Code: Select all

vbox:
    style_prefix "radio"
    label _("Oppai Mode")
    textbutton _("Enabled") action Preference("oppai_mode", True)
    textbutton _("Disabled") action Preference("oppai_mode", False)
And since this mode changes the sprites, in my definitions.rpy file, I added some conditionals to define the sprites:

Code: Select all

if oppai_mode is True:
   ## Adult sprites defined here
else:
   ## Regular sprites here
I also added a default for the prefence in options.rpy:

Code: Select all

default preferences.oppai_mode = False
And even added this into my definitions.rpy file just in case:

Code: Select all

define oppai_mode = False
However when I run the game, I just keep getting a traceback.txt file pop up saying:

Code: Select all

Exception: Preference(u'oppai_mode', True) is unknown.
What am I doing wrong? I could use some advice here as I have not altered the default menus before.

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

Re: How to add a new preference config to settings screen

#2 Post by Imperf3kt » Sun Nov 10, 2019 3:57 pm

Take a look through this thread.
viewtopic.php?f=8&t=42538#p443860

I would suggest using the method it contains.
You might want to start at the top of the thread, the link I gave takes you directly to a working example.
Last edited by Imperf3kt on Sun Nov 10, 2019 4:00 pm, edited 1 time in total.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Todo list:
Actually finish a project

User avatar
thirstyoctopus
Regular
Posts: 60
Joined: Mon Aug 27, 2018 12:04 pm
Projects: Romance Visual Novel story
Organization: Thirsty Octopus
Contact:

Re: How to add a new preference config to settings screen

#3 Post by thirstyoctopus » Sun Nov 10, 2019 4:00 pm

Thanks, I'll check it out and let you know if it did the trick!

User avatar
thirstyoctopus
Regular
Posts: 60
Joined: Mon Aug 27, 2018 12:04 pm
Projects: Romance Visual Novel story
Organization: Thirsty Octopus
Contact:

Re: How to add a new preference config to settings screen

#4 Post by thirstyoctopus » Sun Nov 10, 2019 5:50 pm

Imperf3kt wrote:
Sun Nov 10, 2019 3:57 pm
Take a look through this thread.
viewtopic.php?f=8&t=42538#p443860

I would suggest using the method it contains.
You might want to start at the top of the thread, the link I gave takes you directly to a working example.
Hi again, I checked the thread and although it technically works (I can switch my mode on and off within the game and my debug logs register this) it doesn't really do the job, as this 'mode' affects the defined sprites of the game which are within my definitions.rpy file. My guess is that this is read once only and since my variable is False as default, it doesn't matter if you turn it on when you start playing. The only way around this that I can think is to keep checking that persistent variable every time I change sprites which will be very time consuming and a bit overkill. Is there another way to be able to do this?

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

Re: How to add a new preference config to settings screen

#5 Post by Imperf3kt » Sun Nov 10, 2019 8:22 pm

You should be able to use the variable with a layered image, which would be much more efficient than the way shown for text in the linked thread.

https://www.renpy.org/doc/html/layeredi ... ht=layered
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Todo list:
Actually finish a project

User avatar
thirstyoctopus
Regular
Posts: 60
Joined: Mon Aug 27, 2018 12:04 pm
Projects: Romance Visual Novel story
Organization: Thirsty Octopus
Contact:

Re: How to add a new preference config to settings screen

#6 Post by thirstyoctopus » Mon Nov 11, 2019 6:24 pm

Imperf3kt wrote:
Sun Nov 10, 2019 8:22 pm
You should be able to use the variable with a layered image, which would be much more efficient than the way shown for text in the linked thread.

https://www.renpy.org/doc/html/layeredi ... ht=layered
Thanks, seems to be the best way - however I can tell this will take a looong time to do since I have so many sprite references :? Looks like I might have to make this a standalone game instead of DLC since I'll be changing the whole sprite functionality.

Post Reply

Who is online

Users browsing this forum: trooper6