What I'm trying to do:
At the point where the player is asked their name, I want to filter the input to warn the player when he/she types a rude word or combination of rude words stipulated in an external file bannedwords.txt.
How I do it:
Here's the section of code that defines the function which will decide if a banned word or words have been entered (I actually got a lot of this code from another post, as someone else wanted the same thing):
Code: Select all
python:
import collections
def ContainsBannedWord(name):
# Get list of bad words from a text file, each word on a separate line
bannedWordsList = [line.rstrip('\n') for line in open(renpy.file("../bannedwords.txt"), "r")]
# Check if the name contains a bad word
for bannedWord in bannedWordsList:
if (bannedWord in name):
return True
Code: Select all
$ player_name = renpy.call_screen("input", prompt="Tell me your name:")
Code: Select all
screen input(prompt):
modal True
zorder 200
style_prefix "confirm"
add "gui/overlay/confirm.png"
frame:
vbox:
xalign .5
yalign .5
spacing 30
text prompt
input id "input" color gui.input_text_color
Code: Select all
if (ContainsBannedWord(player_name.lower().strip())):
$ player_name = renpy.call_screen("input", prompt="Come on, don't be rude to me!")
I get the following error in Ren'py:
Code: Select all
While running game code:
File "game/scripts/mc_scenes/outside/outside1.rpy", line 121, in script
if (ContainsBannedWord(player_name.lower().strip())):
File "game/scripts/mc_scenes/outside/outside1.rpy", line 121, in <module>
if (ContainsBannedWord(player_name.lower().strip())):
File "game/scripts/mc_scenes/outside/outside1.rpy", line 112, in ContainsBannedWord
bannedWordsList = [line.rstrip('\n') for line in open(renpy.file("../bannedwords.txt"), "r")]
TypeError: coercing to Unicode: need string or buffer, file found
Can anyone shed some light on what I'm doing wrong here?