Page 1 of 1
cfgfile.em
Posted: Sat Jul 22, 2006 10:42 pm
by DevGIB
i have the following in a cfg file that i want to read and check if the key exists and then returns a value
this is my cfg file
this is my script
Code: Select all
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
i cant seem to get it to work but

Posted: Sun Jul 23, 2006 11:38 am
by Yukiko
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.
Posted: Thu Jul 27, 2006 5:00 am
by DevGIB
next question is there a way to check if a string has number or non alpha numerics in it?
Posted: Thu Jul 27, 2006 5:33 am
by blah
maby
Code: Select all
Lists badwords
{
word fuck
word shit
word arse
}
and
Code: Select all
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"
Posted: Sat Jul 29, 2006 6:15 pm
by DevGIB
i want it so if someone puts in Dev Gib is ok but if they put in Dev_Gib or devgib1 or 1234 they are all illegal
Posted: Mon Jul 31, 2006 12:33 am
by Bytehawk
This should do the job, tho there are ways to do it less complicated
Code: Select all
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