ID:164691
 
Okay, this is my very basic swear censor.
mob/verb/say(msg as text)
if(cmptext("apple",msg)||cmptext("pear",msg))
src<<"Don't swear!"
else world<<"[src]:[msg]"

but would i replace each swear word with stars in the text, like if you say "blah blah APPLE blah blah" then it says "blah blah ***** blah blah", and if you say "blah blah PEAR blah blah" then it says "blah blah **** blah blah" ?
Just filter it with stars.
var/list/curses = list("apple","pear")
proc
filter(string)
var/stars
for(var/i in curses)
var/pos = findtext(string,i)
while(pos)
var/len = length(pos)
for(varr/i = 1 to len)
stars += "*"
string = copytext(string,1,pos) + stars + copytext(string,pos+len)
pos = findtext(string,i)
return string
In response to Xx Dark Wizard xX
mob
var/list/curses = list("apple","pear")
proc
filter(string)
var/stars
for(var/i in curses)
var/pos = findtext(string,i)
while(pos)
var/len = length(pos)
for(varr/i = 1 to len)//is this bit supposed to say varr or is it a typo?
stars += "*"
string = copytext(string,1,pos) + stars + copytext(string,pos+len)
pos = findtext(string,i)
return string

if i change that typo to say var, it says i is a duplicate definition (obviously), and if i take it out so it just says i=1 to len, it gets no errors but it doesn't work.
In response to Adam753
Oooops... i forgor that was just a proc... my bad...
Okay so I'm really not picking this up very quickly but I thought this would work:
mob
var/list/curses = list("apple","pear")
proc
filter(string)
var/stars
for(var/i in curses)
var/pos = cmptext(string,i)
while(pos)
var/len = length(pos)
for(i = 1 to len)
stars += "*"
string = copytext(string,1,pos) + stars + copytext(string,pos+len)
pos = findtext(string,i)
return string
verb/say(msg as text)
filter(msg)
world<<"[src]:[msg]"

But nothing is filtered...
Aack!! I just found out, if msg IS apple, instead of it having apple in it, it freezes for a few seconds, then gives me a runtime error and goes horrible laggy!!!
In response to Adam753
for(var/j = 1 to len)

msg = filter(msg)
In response to Xx Dark Wizard xX
Nope. If I say apple, I get horrible lag and this:

Infinite loop suspected--switching proc to background.
If it is not an infinite loop, either do 'set background=1' or set world.loop_checks=0.
proc name: filter (/mob/proc/filter)
usr: Adam753 (/mob/player)
src: Adam753 (/mob/player)
call stack:
Adam753 (/mob/player): filter("apple")
Adam753 (/mob/player): Say("apple")

and if I say a sentence with apple in it, nothing gets filtered...
In response to Adam753
Use findtext not cmptext. Don't make it a mob proc either.
In response to Xx Dark Wizard xX
That doesn't help either!!
In response to Adam753
var/list/curses = list("apple","pear")
proc
filter(string)
var/stars
for(var/i in curses)
var/pos = findtext(string,i)
while(pos)
for(var/j = 1 to length(i))
stars += "*"
string = copytext(string,1,pos) + stars + copytext(string,pos+length(i))
pos = findtext(string,i)
return string
mob
verb/say(msg as text)
msg = filter(msg)
world<<"[src]:[msg]"

Read the guide.
In response to Xx Dark Wizard xX
var/list/curses = list("apple","pear")
proc
filter(string)
var/stars
for(var/i in curses)
var/pos = findtext(string,i)
while(pos)
for(var/j = 1 to length(i))
stars += "*"
string = copytext(string,1,pos) + stars + copytext(string,pos+length(i))
pos = findtext(string,i)
return string
mob
verb/say(msg as text)
msg = filter(msg)
world<<"[src]:[msg]"

That doesn't work either? When i say "apple", it says:
Adam753:*************************
And when I say "blah apple blah" it says:
Adam753:blah * blah** * blah*** * blah** * blah**** * blah** * blah*** * blah** * blah***** * blah** * blah*** * blah** * blah**** * blah** * blah*** * blah** * blah
In response to Adam753
var/list/curses = list("apple","pear")
proc
filter(string)
var/stars
for(var/i in curses)
var/pos = findtext(string,i)
while(pos)
for(var/j = 1 to length(i))
stars += "*"
string = copytext(string,1,pos) + stars + copytext(string,pos+length(i))
pos = findtext(string,i)
return string
In response to Xx Dark Wizard xX
YES, finally it works... almost, now if I say "apple apple" it says "Adam753:***** **********"
In response to Adam753
after pos = findtext() do stars = "" and I hope that fixes it.
In response to Xx Dark Wizard xX
w00t it finally works!!! you kept posting ideas over and over again that gave me the same errors... Thanks!
In response to Adam753
Its what happens when I don't compile it in DM beforehand, glad it works. I am probably going to make a library eventually to filter words while catching attempts to bypass it like adding in a space like a pple.