Case sensitivity
by Chris Ratliff · in General Discussion · 04/19/2005 (10:09 pm) · 7 replies
Quick question. I'm running a script that modifies curse words spoken in game. It works well, however there is one problem. If they type the word in all caps or just the first letter and it isnt on the list, it allows it to come up in game. Is there a way I could have it check text and look for and replace the words regardless of the case? This would be nice. Otherwise I have to repeat the words in the list approx 500 Mil times to get all forms of cases that can be used to type it in. Any suggestions?
About the author
#2
in this case I would say %string would need to be compared with $bannedWords, however I have not been able to make this happen correctly. Any ideas on how this would work or where exactly I would put it. There is a small line of script that intiates the read code to the posted script above. I dont remember where exactly I got this curse omitter script but it does work well, all except the case sensitive stuff.
04/20/2005 (1:43 pm)
Ok heres my prob, I've tried several different ways but still cant seem to get it right. Heres a snipit from the read code of the string. Where exactly would I put the strcmp function at to make it work correctly?{
for(%i=0; %i<$numBannedWords; %i++)
{
%string = Strreplace( %string, $bannedWords[%i], replacementWord[%i] );
}
return %string;
}in this case I would say %string would need to be compared with $bannedWords, however I have not been able to make this happen correctly. Any ideas on how this would work or where exactly I would put it. There is a small line of script that intiates the read code to the posted script above. I dont remember where exactly I got this curse omitter script but it does work well, all except the case sensitive stuff.
#3
04/20/2005 (2:14 pm)
I would say before the strreplace and place the strreplace in an if block defined by the strcmp
#4
%newString = strlwr(%myString);
The function 'strlwr();' will convert the inputted '%myString' to lowercase. Now you can just compare it to the lowercase version! =)
Also, if you want to continue to use the string compare function there is a version of that function that is case-insenstive:
Stricmp(%string1,%string2);
07/08/2005 (9:25 am)
When you are comparing, use this function:%newString = strlwr(%myString);
The function 'strlwr();' will convert the inputted '%myString' to lowercase. Now you can just compare it to the lowercase version! =)
Also, if you want to continue to use the string compare function there is a version of that function that is case-insenstive:
Stricmp(%string1,%string2);
#5
-Dan
07/08/2005 (9:47 am)
I'm guessing you don't really want to compare yourself - you just want a version of StrReplace that does a case-insensitive find and then replaces. I'm not sure if such a thing exists offhand, though adding it to the engine wouldn't be difficult. If you (Chris) need help adding that to the engine, let us know.-Dan
#6
What I ended up doing is looping through the message word by word, using strlwr and strcmp together, if the lower case version of the word matches the command word then remove the command word from text and take action.
Exact same principle could be used for a badword filter.
If the word is not what you are looking for then you just move on to the next word and leave the word the way you found it.
04/30/2006 (10:28 pm)
I ran into a similar problem when trying to make the chat system recognize and respond to slash commands.What I ended up doing is looping through the message word by word, using strlwr and strcmp together, if the lower case version of the word matches the command word then remove the command word from text and take action.
Exact same principle could be used for a badword filter.
If the word is not what you are looking for then you just move on to the next word and leave the word the way you found it.
#7
05/06/2006 (9:38 am)
I actually came up with a working script for this... I also managed to come up with a Private Ingame Messenger using similar functions that I found in the curse filter script. Thanks for all ur input guys...
Torque 3D Owner Michael Cozzolino
Big Monk Games
Strcmp(str1,str2)
You could try comparing the input as str1 and loop through your list with str2