ID:261449
 
PLease help me fix this code:

mob/verb/Say(msg as text)
if(!msg)
return
if(msg == "fuck")
msg = "****"
world <<"[usr]: [msg]"
else
world <<"[usr]: [msg]"

It works.So when i say fuck it works,BUT when i put another word in it besides fuc*k.It doesn't work.Thanks!

-Non-PC
Non-PC wrote:
PLease help me fix this code:

> mob/verb/Say(msg as text)
> if(!msg)
> return
> if(msg == "fuck")
> msg = "****"
> world <<"[usr]: [msg]"
> else
> world <<"[usr]: [msg]"
>
>

It works.So when i say fuck it works,BUT when i put another word in it besides fuc*k.It doesn't work.Thanks!

-Non-PC

Worked fine when I tested it.

-Kappa the Imp
In response to Kappa the Imp
Worked fine when I tested it.

I sincerely doubt that. =P
In response to Kappa the Imp
Kappa the Imp wrote:
Non-PC wrote:
PLease help me fix this code:

> > mob/verb/Say(msg as text)
> > if(!msg)
> > return
> > if(msg == "fuck")
> > msg = "****"
> > world <<"[usr]: [msg]"
> > else
> > world <<"[usr]: [msg]"
> >
> >

It works.So when i say fuck it works,BUT when i put another word in it besides fuc*k.It doesn't work.Thanks!

-Non-PC

Worked fine when I tested it.

-Kappa the Imp

No,no,no try putting a word after it.

-Non-PC
In response to Non-PC
Non-PC wrote:
Kappa the Imp wrote:
Non-PC wrote:
PLease help me fix this code:

> > > mob/verb/Say(msg as text)
> > > if(!msg)
> > > return
> > > if(msg == "fuck")
> > > msg = "****"
> > > world <<"[usr]: [msg]"
> > > else
> > > world <<"[usr]: [msg]"
> > >
> > >

It works.So when i say fuck it works,BUT when i put another word in it besides fuc*k.It doesn't work.Thanks!

-Non-PC

Worked fine when I tested it.

-Kappa the Imp

No,no,no try putting a word after it.

-Non-PC

Oh,I see.Sorry,I don't know how to fix that.
Good Luck Getting Help!


-Kappa the Imp

In response to Kappa the Imp
//Filter system 1.0
proc/SGS_Filter_txt(txt)
var/stars
var/s_amount
var/mem
var/find_t
var/txtLen
var/Words[]
Words = new /list/
Words = list("fuck","shit","jerk","bitch")//you can add words here to filter
if(Words.len)
memo:
for(mem = 1,mem < Words.len + 1,mem++)
find_t = findtext(txt,Words[mem])
if(find_t)
txtLen = length(Words[mem])
stars = null
s_amount = null
for(s_amount = 0,s_amount < txtLen,s_amount++)
stars += "*"
txt = copytext(txt,1,find_t) + stars + copytext(txt,find_t+txtLen,0)
if(findtext(txt,Words[mem])) goto memo
return txt

In response to Justin Sun
Now where have I seen Justin Sun's code before..?? O yea Safe Guard Suite:P
In response to Justin Sun
Justin Sun wrote:
//Filter system 1.0
proc/SGS_Filter_txt(txt)
var/stars
var/s_amount
var/mem
var/find_t
var/txtLen
var/Words[]
Words = new /list/
Words = list("fuck","shit","jerk","bitch")//you can add words here to filter
if(Words.len)
memo:
for(mem = 1,mem < Words.len + 1,mem++)
find_t = findtext(txt,Words[mem])
if(find_t)
txtLen = length(Words[mem])
stars = null
s_amount = null
for(s_amount = 0,s_amount < txtLen,s_amount++)
stars += "*"
txt = copytext(txt,1,find_t) + stars + copytext(txt,find_t+txtLen,0)
if(findtext(txt,Words[mem])) goto memo
return txt


Nope.I don't want to use a proc in my say verb.I want MY code fixed because its the shortest way I think off to code it.

-Non-PC
In response to Kappa the Imp
You could add all the words into one list and check it against that


var/list/wordlist = list("Word1","Word2",Word3")

mob/verb/Say(T as text)
if(wordlist.Find(T))
msg = "****"
world << "[usr]: [T]"
else
world << "[usr]: [T]"
I recommend you take a look at the code in my last Dream Tutor column for BYONDscape. Included in there is a very reasonable language filter that should fit your needs.

Lummox JR
In response to Nadrew
Nadrew wrote:
You could add all the words into one list and check it against that


> var/list/wordlist = list("Word1","Word2",Word3")
>
> mob/verb/Say(T as text)
> if(wordlist.Find(T))
> msg = "****"
> world << "[usr]: [T]"
> else
> world << "[usr]: [T]"
>


Nope.If you type a text after it(a word)it doesn't work.

-Non-PC
In response to Non-PC
Then you'd do something like this in the if()

if(findtext(T,wordlist.Find(T)))
...
In response to Nadrew
??????????Whats wrong with this code?:

var/list/wordlist = list("Word1","Word2","Word3")

mob/verb/Say(T as text)
if(findtext(T,wordlist.Find(T)))

T = "****"
world << "[usr]: [T]"
else
world << "[usr]: [T]"

Now,everything I say comes out as stars.

-Non-PC



In response to Non-PC
Let me get some sleep and I'll get back to you. (For all of you that don't know I sleep during the day now)
In response to Non-PC
Non-PC wrote:
??????????Whats wrong with this code?:
var/list/wordlist = list("Word1","Word2","Word3")

mob/verb/Say(T as text)
if(findtext(T,wordlist.Find(T)))

T = "****"
world << "[usr]: [T]"
else
world << "[usr]: [T]"

Now,everything I say comes out as stars.

That's because you're replacing the entire string, instead of just the offending part of it. But also, you're using wordlist.Find() wrong. You need to loop through every word in the list, like this:
mob/verb/Say(T as text)
for(var/cussword in wordlist)
i=findtext(T,cussword)
while(i)
T=copytext(1,i)+"@#$%&!"+copytext(i+length(cussword))
i=findtext(T,cussword,i+6) // start after @#$%&!
world << "[usr]: [T]"

This works now, but it's a very very poor swear filter. For one thing, it won't recognize whole words, so you could end up with problems like this:

Goofball128: I don't mean to h@#$%&!le you, but could you p@#$%&! the salt?
Crackpot: You have to say the p@#$%&!word first.

Of course the F word is fine to recognize this way, because it doesn't occur naturally in other English words.

My recent Dream Tutor column has more on this subject, including working code for a good language filter.

Lummox JR
In response to Lummox JR
Thanks for clearing that up for him. I promise never to help in my current state of mind again.
In response to Lummox JR
Thanks Lummox!

-Non-PC