View Single Post
nergal
Veteran Member
Join Date: Apr 2012
Old 09-28-2020 , 13:09   Re: [SP] ConfigMap: StringMap & SMCParser
Reply With Quote #10

Quote:
Originally Posted by MAGNAT2645 View Post
That's just a stock which returns true (only if string treated as true) or false (in any other case), you don't have to use it. It was just an example of simple/advanced conversion.
alright, put this code in your cfgmap.inc and test out how it goes:

Code:
	public int GetBool(const char[] key_path, bool& b, bool simple=true) {
		if( this==null ) {
			return 0;
		}
		PackVal val;
		bool result = this.GetVal(key_path, val);
		if( result && val.tag==KeyValType_Value ) {
			val.data.Reset();
			char[] strval = new char[val.size];
			val.data.ReadString(strval, val.size);
			if( simple ) {
				b = StringToInt(strval) != 0;
			} else {
				if( !strcmp(strval, "true", false) || !strcmp(strval, "1", false) ) {
					b = true;
				} else if( !strcmp(strval, "false", false) || !strcmp(strval, "0", false) ) {
					b = false;
				} else {
					return 0;
				}
			}
			return val.size - 1;
		}
		return 0;
	}
__________________

Last edited by nergal; 09-28-2020 at 13:10.
nergal is offline