Jump to content


Photo
- - - - -

Word Filter Example


  • Please log in to reply
5 replies to this topic

#1 CrazyGamer

CrazyGamer

    GMC Member

  • GMC Member
  • 80 posts

Posted 13 January 2012 - 01:43 AM

Title: World Filter
Description: Filters chosen words from a string replacing them with "***"
GM Version: gm8.0
Registered: No
File Type: .gmk
File Size: 10.66 Kb
File Link: MediaFire

This example shows you how to make a word filter.It can be useful for filtering chat in online games :) .
The example contains 4 scripts it is well commented and easy to understand by anyone with a little gml knowledge.
BTW:Filters have ids so u can use more than one different filter in the same object :)
Credits goes to CrazyGamer if used :) (only if you want)
  • 0

#2 Debels

Debels

    GMC Member

  • GMC Member
  • 1997 posts
  • Version:GM:Studio

Posted 13 January 2012 - 02:38 AM

Title: World Filter
Description: Filters chosen words from a string replacing them with "***"
GM Version: gm8.0
Registered: No
File Type: .gmk
File Size: 10.66 Kb
File Link: MediaFire

This example shows you how to make a word filter.It can be useful for filtering chat in online games :) .
The example contains 4 scripts it is well commented and easy to understand by anyone with a little gml knowledge.
BTW:Filters have ids so u can use more than one different filter in the same object :)
Credits goes to CrazyGamer if used :) (only if you want)


Theres 1 thing i dont like from this:

it filters ugly but it doesn't filter uuuuuuuuuuuuuuuuuuuuugggggggggggggggggggggggggggglllllllllllllllllllllllllllllllllllllllllllllyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, so.....
  • 0

#3 CrazyGamer

CrazyGamer

    GMC Member

  • GMC Member
  • 80 posts

Posted 13 January 2012 - 09:58 AM


Title: World Filter
Description: Filters chosen words from a string replacing them with "***"
GM Version: gm8.0
Registered: No
File Type: .gmk
File Size: 10.66 Kb
File Link: MediaFire

This example shows you how to make a word filter.It can be useful for filtering chat in online games :) .
The example contains 4 scripts it is well commented and easy to understand by anyone with a little gml knowledge.
BTW:Filters have ids so u can use more than one different filter in the same object :)
Credits goes to CrazyGamer if used :) (only if you want)


Theres 1 thing i dont like from this:

it filters ugly but it doesn't filter uuuuuuuuuuuuuuuuuuuuugggggggggggggggggggggggggggglllllllllllllllllllllllllllllllllllllllllllllyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, so.....

That's because it searches for words you added to the filter. so it will only filter what you add. I don't think it's possible to make it search for "ugly" and it finds "uuuuuuuuugggggglllllllyyyyyy" . I think that's simply impossible .When someone will be able to do that in gml please tell me .
  • 0

#4 Dark Matter

Dark Matter

    RPG Expert

  • GMC Member
  • 3196 posts
  • Version:GM:Studio

Posted 13 January 2012 - 04:59 PM

You don't want it to filter words with extra characters like that. Although it'd be fairly easy to do in GM, you'd filter words that weren't supposed to be. For example, say the word "bot" should be filtered. "boot" is a completely different word, yet you'd end up filtering that too. There's no good way to filter stuff like that, except to manually moderate it.
  • 0

#5 loverock125

loverock125

    GMC Member

  • GMC Member
  • 1597 posts
  • Version:GM8

Posted 13 January 2012 - 06:20 PM

I think that's simply impossible .When someone will be able to do that in gml please tell me .



I just did it : D

/*
filter(text)
*/
var i,curChar,newText;
newText = "";

for(i=1;i<=string_length(argument0);i+=1)
{
curChar = string_char_at(argument0,i);

    if curChar!=string_char_at(argument0,i-1)
    {
    newText+=curChar;
    }
}


if string_lower(newText) = "ugly"
{
return("****");
}


return(argument0);


But as Dark Matter said, it's not good at all to do this since it will filter appropriate words as well, which is why there's no online game filters this way.

Back to your project, there is one tiny bug which is very easy to fix. It filters the word 'ugly' but does not filter the word 'Ugly'.
It's very easy to fix by converting the text into lower characters just before filtering (Which is what I did in the code above). Just use string_lower before filtering.

Good luck!


Edit: In case you don't know what to do, in the script filter_string replace line 6 with this:
i=1;newstr=string_lower(argument1);

Edited by loverock125, 13 January 2012 - 06:22 PM.

  • 0

#6 CrazyGamer

CrazyGamer

    GMC Member

  • GMC Member
  • 80 posts

Posted 13 January 2012 - 08:24 PM


I think that's simply impossible .When someone will be able to do that in gml please tell me .



I just did it : D

/*
filter(text)
*/
var i,curChar,newText;
newText = "";

for(i=1;i<=string_length(argument0);i+=1)
{
curChar = string_char_at(argument0,i);

    if curChar!=string_char_at(argument0,i-1)
    {
    newText+=curChar;
    }
}


if string_lower(newText) = "ugly"
{
return("****");
}


return(argument0);


But as Dark Matter said, it's not good at all to do this since it will filter appropriate words as well, which is why there's no online game filters this way.

Back to your project, there is one tiny bug which is very easy to fix. It filters the word 'ugly' but does not filter the word 'Ugly'.
It's very easy to fix by converting the text into lower characters just before filtering (Which is what I did in the code above). Just use string_lower before filtering.

Good luck!


Edit: In case you don't know what to do, in the script filter_string replace line 6 with this:
i=1;newstr=string_lower(argument1);

I didn't think of that way :-? but even if it is possible as Dark Matter said it would be not a good way because it might filter unwanted words .
And about the bug, thanks, nice observation, i forgot of that. ill edit it and add a new one.

Edited by CrazyGamer, 13 January 2012 - 08:24 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users