Page 1 of 1

How to add a new preference config to settings screen

Posted: Sun Nov 10, 2019 12:14 pm
by thirstyoctopus
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.

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

Posted: Sun Nov 10, 2019 3:57 pm
by Imperf3kt
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.

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

Posted: Sun Nov 10, 2019 4:00 pm
by thirstyoctopus
Thanks, I'll check it out and let you know if it did the trick!

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

Posted: Sun Nov 10, 2019 5:50 pm
by thirstyoctopus
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?

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

Posted: Sun Nov 10, 2019 8:22 pm
by Imperf3kt
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

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

Posted: Mon Nov 11, 2019 6:24 pm
by thirstyoctopus
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.