AntiSwear -> while & for loops errors :/ - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: AntiSwear -> while & for loops errors :/ (
/showthread.php?tid=479930)
AntiSwear -> while & for loops errors :/ -
erminpr0 - 07.12.2013
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;
}
Re: AntiSwear -> while & for loops errors :/ -
Jefff - 08.12.2013
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] = '*';
}
Re: AntiSwear -> while & for loops errors :/ - Astralis - 08.12.2013
better use str_replace, easiest and simpliest way.
Re: AntiSwear -> while & for loops errors :/ -
erminpr0 - 08.12.2013
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! (: