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
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}?"
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
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.