[SOLVED] How can I create custom content preferences?

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
limpciabatta
Newbie
Posts: 13
Joined: Sun Feb 19, 2023 10:22 pm
Contact:

[SOLVED] How can I create custom content preferences?

#1 Post by limpciabatta »

I'd like to add custom content preferences to the Preferences screen in my game, but I'm not entirely sure how I need to code them.
What I want to provide is a menu/list of content topics that are enabled by default and players can click on them to disable them, that way the players can skip past that content in the game without seeing it.

So, for example:

Content Preferences (label)
  • Peppers (check button)
  • Beaches (check button)
  • Dogs (check button)
As a player who doesn't like peppers, I want to disable/skip past the content related to peppers in the game, so I'd click on "Peppers" to disable it.

In screens.rpy, under the preferences screen section, how should I go about coding this? For instance, can I use something like the following:

Code: Select all

textbutton _("Peppers") action Preference("toggle", $ persistent.turnoffpeppers = True)
Or is there some other way I should be going about doing this?


As for the in-game content in the script, would it be safe to assume that I can then use whatever variable I set for the content preference button in the following fashion?

Code: Select all


charactername1 "What did you buy at the grocery store?"

if persistent.turnoffpeppers == True:
	charactername2 "I bought grapes, cheese, and meat."
	jump section_conversationcontinued

charactername2 "I bought grapes, cheese, peppers, and meat."

label section_conversationcontinued:
	#This is where the characters continue their conversation
If not, how should I go about this in the game content?

Thanks very much!
Last edited by limpciabatta on Wed Jan 03, 2024 6:03 pm, edited 1 time in total.

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

Re: How can I create custom content preferences?

#2 Post by m_from_space »

limpciabatta wrote: Tue Jan 02, 2024 11:36 am I'd like to add custom content preferences to the Preferences screen in my game, but I'm not entirely sure how I need to code them.
It's pretty easy actually. Here is what I do in my project. Let's assume we have a custom setting called "nudity" (for obvious reasons). But don't use Preference(), that's for Renpy internal preferences.

Code: Select all

# create a default value for that persistent variable
default persistent.nudity = False

screen preferences():
    tag menu
    
    # show a check button for that specific variable
    textbutton "Show Nudity" action ToggleField(persistent, "nudity") style_prefix "check"
In game:

Code: Select all

label start:
    if persistent.nudity:
        show eileen nude
    else:
        show eileen

limpciabatta
Newbie
Posts: 13
Joined: Sun Feb 19, 2023 10:22 pm
Contact:

Re: How can I create custom content preferences?

#3 Post by limpciabatta »

Thanks a bunch, it looks like that did the trick! Marking this as solved, I really appreciate your assistance on this! :)

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot], Milkymalk