AntiSwear -> while & for loops errors :/
#1

Hello, I have tried to make AntiSwear function which replaces bad words to ******

Here is my code, I have founded on forum, and copied, so tried to make but doesn't work..

I got errors in loops ( ill comment errors in code )

Please help me, rep++

Код:
new BadWords[][] =
{
	{"bot"},
	{"noob"},
	{"idiot"},
	{"fuck"},
	{"fag"}
};

stock AntiSwear(string[])
{
    new s ;
    while((s = strfind(string, BadWords[], true)) != -1) // error 029: invalid expression, assumed zero
    {
        for(new x = (s + strlen(BadWords[])); s != x; ++s) // error 029: invalid expression, assumed zero
        {
            string[s] = '*';
        }
    }
    return 1;
}

// So usage would be:
// Ex:
public OnPlayerText(playerid, text)
{
   AntiSwear(text);
   return 0;
}
Reply
#2

pawn Код:
stock AntiSwear(string[])
{
    new pos;

    for(new x=0; x != sizeof(BadWords); x++)
        while((pos = strfind(string, BadWords[x], true)) != -1)
            for(new i = pos+1, j = pos + strlen(BadWords[x])-1; i < j; i++)
                string[i] = '*';

}
Reply
#3

better use str_replace, easiest and simpliest way.
Reply
#4

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
stock AntiSwear(string[])
{
    new pos;

    for(new x=0; x != sizeof(BadWords); x++)
        while((pos = strfind(string, BadWords[x], true)) != -1)
            for(new i = pos+1, j = pos + strlen(BadWords[x])-1; i < j; i++)
                string[i] = '*';

}
Thanks,works but I have changed the start pos to 0 and end with last character, cuz
i don't want:

i***t
i want, *****

Thank you! (:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)