function checkname(name)
var hisname := lower(name);
var cfg := ReadConfigFile("::badnames");
var wordelem := FindConfigElem(cfg, "badwords");
var nameelem := FindConfigElem(cfg, "badnames");
foreach word in SplitWords(hisname)
var chk := GetConfigString( wordelem, word );
if (chk)
return 0;
endif
endforeach
var nmchk := GetConfigString( nameelem, hisname );
if (!nmchk)
return 1;
else
return 0;
endif
endfunction
You have this line:
var nameelem := FindConfigElem(cfg, "badnames");
but where is the element "badnames"?
Also in the 'for' loop you are parsing through the multiple words in hisname but it doesn't appear that you are parsing through each word entry for wordelem.
GetConfigStringArray( element, property_name )
* Explanation :
For elements with multiple occurrences of a given property, returns an array containing each occurrence.
For example, to get all the ingredients in the following element:
Dessert applepie
{
Cost 8
Calories 1004
MadeLike grandma
Ingredient flour
Ingredient butter
Ingredient apples
Deliciousness 3.6
}
Use: 'var ingredients := GetConfigStringArray(element,"Ingredient");'
'ingredients' now contains 'flour', 'butter', and 'apples'.
Value of the properties are always returned as strings. If the values are ints or reals, use CInt() or CDbl() to cast the values to the correct type.
* Return values
An array of strings.
* Errors
"Invalid parameter type"
use uo;
program dummyprog(who)
// Let the user enter a text
var answer:= RequestInput (who, who.backpack, "Your answer?");
// He entered nothing or the first char was a number
if (!answer || (CInt (answer) > 0))
SendSysMessage (who, "Cancelled");
return 0;
endif
// Call the function to check the string
if (check_string(answer))
SendSysMessage (who, "String doesn't contain any invalid characters");
else
SendSysMessage (who, "String DOES contain invalid characters");
endif
endprogram
/* checks <mystring> for invalid characters
*
* returns 1 if <mystring> contains no invalid characters
* 0 if <mystring> has invalid characters
*/
function check_string(mystring)
// These are the unwanted characters
var forbidden:= array {"_", "@", "-",
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
var i:= 0;
// Check each single character of the string if it is contained in the array
// of forbidden characters
for (i:= 1; i <= len (mystring); i:= i + 1)
if (mystring[i] in forbidden)
return 0;
endif
endfor
return 1;
endfunction