Okay, so not quite, since I tried it and some filtered words got through. I was thinking more along the lines of this, but I keep getting an error.
Code: Select all
init python:
import re
def filter_bad_words(input, replace_with="unicorn"):
approved_name_list = ['Hope', 'Michelle', 'Rochelle']
if input != None:
if input in approved_name_list:
message = "Approved Name"
renpy.show_screen("popup_message", message=message)
else:
with renpy.file('bad_words.txt') as f: ## adjust the file name and folder to suit
bad_words = [ ln.strip() for ln in f ]
exp = '({})'.format( "|".join( bad_words ) )
r = re.compile(exp, re.IGNORECASE)
return r.sub(replace_with, input)
screen popup_message(message):
text str(message)
timer 3 action Hide("popup)message")
label naming:
$ player = filter_bad_words(
renpy.input(
"What is her name? (Type in a name, 10 characters max.",
allow=" 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
length=10).strip().title(),
replace_with = "Fluffy Wabbit" )
if "Fluffy Wabbit" in player:
"Not acceptable, please give her a proper name."
jump naming
The error is this:
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 74, in script
if "Fluffy Wabbit" in player:
File "game/script.rpy", line 74, in <module>
if "Fluffy Wabbit" in player:
TypeError: argument of type 'NoneType' is not iterable
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 74, in script
if "Fluffy Wabbit" in player:
File "G:\Creative\VN\Renpy\renpy\ast.py", line 1762, in execute
if renpy.python.py_eval(condition):
File "G:\Creative\VN\Renpy\renpy\python.py", line 1944, in py_eval
return py_eval_bytecode(code, globals, locals)
File "G:\Creative\VN\Renpy\renpy\python.py", line 1937, in py_eval_bytecode
return eval(bytecode, globals, locals)
File "game/script.rpy", line 74, in <module>
if "Fluffy Wabbit" in player:
TypeError: argument of type 'NoneType' is not iterable
Windows-7-6.1.7601-SP1
Ren'Py 7.1.3.1092
LearningPython 1.0
Mon Feb 18 13:27:05 2019