[Solved]Custom Profanity filter keeps resetting at main menu

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
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

[Solved]Custom Profanity filter keeps resetting at main menu

#1 Post by Imperf3kt » Thu Feb 16, 2017 5:10 am

Hi, in my game I decided to add a filter for users to decide if they wanted swearing in the game or not. My original script has mild coarse language and I figured some users would prefer to have no course language.

So in my preferences screen I added the option with the following code:

Code: Select all

vbox:
                    style_prefix "radio"
                    label _("Profanity")
                    textbutton _("Block") action SetVariable ("profanity", 0)
                    textbutton _("Allow") action SetVariable ("profanity", 1)
And then I made some additions within an init-2 block just before label start:, that check the variable.

Code: Select all

init -2:
    if profanity == 0:
        $ shit = _("Crap")
    elif profanity == 1:
        $ shit = _("Shit")

label start:
And in the script, it is invoked by something like:

Code: Select all

    mcs "[shit!t], already?"
But, after thinking about this, the way I was doing it was less than ideal. I'd have a long list of words by the time I was done, and making sure I had everything right would be a headache.


I modified my code to the following:

Code: Select all

init -2:
    default profanity = 0

label start:
And invoke it with:

Code: Select all

    if profanity == 0:
        mcs "Crap, already?"
    elif profanity == 1:
        mcs "Shit, already?"
More typing, I know, but it is a lot easier to work with and less room for error.

My problem is, that whenever I click "allow" in the preferences menu, it only stays "allowed", whilst browsing the menu's and playing the game. If a user returns to the main menu, or reaches the end of the script, thus also returning to the main menu, profanity = 1 reverts to profanity = 0 every time.

Am I doing it wrong, because I feel the option should stay the same, like the other options in preferences menu do.

Preferences when the game first starts (and every time you load it again)
screenshot0028.png
Default
Preferences whilst in-game, having selected to allow profanity
screenshot0029.png
profanity = 1
But as soon as you reach the end of the script or return to the main menu, it returns to it's default state.
Loading a game, previously saved with profanity allowed, stays allowed.

Edit: Game code removed as it was a massive WOT (Wall Of Text) and the issue has been resolved, so it is now unnecessary.
Last edited by Imperf3kt on Fri Feb 17, 2017 3:35 am, edited 3 times in total.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: Custom "Profanity filter" keeps resetting at main menu

#2 Post by Divona » Thu Feb 16, 2017 5:52 am

My problem is, that whenever I click "allow" in the preferences menu, it only stays "allowed", whilst browsing the menu's and playing the game. If a user returns to the main menu, or reaches the end of the script, thus also returning to the main menu, profanity = 1 reverts to profanity = 0 every time.

Am I doing it wrong, because I feel the option should stay the same, like the other options in preferences menu do.
Use persistent:

Code: Select all

define persistent.profanity = 0

label start:
    . . .

    if persistent.profanity == 0:
        mcs "Crap, already?"
    elif persistent.profanity == 1:
        mcs "Shit, already?"
In "screens.rpy":

Code: Select all

vbox:
    style_prefix "radio"
    label _("Profanity")
    textbutton _("Block") action SetField(persistent, "profanity", 0)
    textbutton _("Allow") action SetField(persistent, "profanity", 1)
Completed:
Image

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

Re: Custom "Profanity filter" keeps resetting at main menu

#3 Post by Imperf3kt » Thu Feb 16, 2017 6:49 am

I tried persistent.profanity but it only threw errors within SetVariable. Somehow this didn't get posted with the rest of my message.

Your explanation seems to have done the trick though, thank you very much.
My issue was in screens.rpy, I tried:

Code: Select all

textbutton _("Block") action SetField(persistent.profanity, 0)
textbutton _("Allow") action SetField(persistent.profanity, 1)
When I should have used:

Code: Select all

textbutton _("Block") action SetField(persistent, "profanity", 0)
textbutton _("Allow") action SetField(persistent, "profanity", 1)
Thank you again for the help, it works like a charm.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

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

Re: Custom "Profanity filter" keeps resetting at main menu

#4 Post by Imperf3kt » Thu Feb 16, 2017 7:33 pm

Hello again. Small problem,
If a player does not go to the options menu and select their preference, the lines are skipped altogether and neither variant is shown.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: Custom "Profanity filter" keeps resetting at main menu

#5 Post by Divona » Thu Feb 16, 2017 11:14 pm

Imperf3kt wrote:Hello again. Small problem,
If a player does not go to the options menu and select their preference, the lines are skipped altogether and neither variant is shown.
Did you define the persistent variable?

Code: Select all

define persistent.profanity = 0

label start:
    . . .
Load from previous save could have problems because the variable wasn't there in the save.
Completed:
Image

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

Re: Custom "Profanity filter" keeps resetting at main menu

#6 Post by Imperf3kt » Fri Feb 17, 2017 3:33 am

That did the trick. I did write it in, but I did further editing afterwards, and it seems that somewhere in my edit / undo / redo, I undid it.

Thanks, all good now.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

Post Reply

Who is online

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