Problem implementing custom automatic profanity filter.

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
ChroniclerOfLegends
Regular
Posts: 53
Joined: Thu Feb 16, 2017 5:57 pm
Projects: Scifi Non-Linear Visual Novel/Arcade/Adventure game. (No name yet)
Contact:

Problem implementing custom automatic profanity filter.

#1 Post by ChroniclerOfLegends »

Hello,

I had asked a question before about using a profanity filter, but this is more specifically a technical difficulty so I figured I would post my question here. Sorry ahead of time if you don't want a second post.

I am trying to create a custom profanity filter tag that replaces tagged words if a certain variable is set. It automatically creates a '****' string the same length of the word that is tagged if profanity is toggled off by the player.

I am using this article to try and create it:
https://www.renpy.org/doc/html/custom_text_tags.html

and this is my implementation code:

Code: Select all

init python:
    ### A custom tag for tagging words that should be censored
    ### USE:  "Suddenly a wild {c}duck{/c} appeared before me."
    ### RESULT: "Suddenly a wild **** appeared before me."
    def c_tag(tag, argument, contents):
        if (profanity_level == 'CNT'):
            strLen = len(contents[1])
            rs = []
            count = 0
            while (count < strLen):
                rs.append((renpy.TEXT_TEXT, '*'))
                count += 1
            return rs
        else:
            return [contents]
        
    config.custom_text_tags["c"] = c_tag
And this is the line I am testing it with:

Code: Select all

    $ profanity_level = 'CN'
    "Censoring turned off: Have you seen my {c}duck{/c}?"
    $ profanity_level = 'CNT'
    "Censoring turned on: Have you seen my {c}duck{/c}?"
I get this error:

Code: Select all

 
I'm sorry, but an uncaught exception occurred.

While running game code:
 File "game/source/scenes/init_variables.rpy", line 130, in script call
    call playersetup from _call_playersetup
  File "game/source/scenes/scene_debug.rpy", line 46, in script
    "Censoring turned off: Have you seen my {c}duck{/c}?"
ValueError: need more than 1 value to unpack
Anybody understand what the ValueError means?
I thought it had something to do with giving the tag an argument, but even when I give it an argument (EX: {c=profanity_level} or {c='****'}) I get the same error.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Problem implementing custom automatic profanity filter.

#2 Post by Remix »

contents is already a list (actually a tuple iirc), so
return [contents]
should be
return contents

You could simplify btw:
return [ (renpy.TEXT_TEXT, '*' * len(contents[1]) ) ]

or alternatively use config.say_menu_text_filter to run a function that does find->replace on all dialogue without having to code {c} and {/c} each time
Frameworks & Scriptlets:

User avatar
ChroniclerOfLegends
Regular
Posts: 53
Joined: Thu Feb 16, 2017 5:57 pm
Projects: Scifi Non-Linear Visual Novel/Arcade/Adventure game. (No name yet)
Contact:

Re: Problem implementing custom automatic profanity filter.

#3 Post by ChroniclerOfLegends »

Thank you very much, got it working now :)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], henne, Ocelot