Raised This Month: $ Target: $400
 0% 

[SP] ConfigMap: StringMap & SMCParser


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
nergal
Veteran Member
Join Date: Apr 2012
Old 09-27-2020 , 18:21   Re: [SP] ConfigMap: StringMap & SMCParser
Reply With Quote #8

Quote:
Originally Posted by MAGNAT2645 View Post
I have this stock:
Code:
#define _BOOL(%1) view_as< bool >( %1 )

stock bool StringToBool(const char[] str, bool simple=true) {
	if ( simple )
		return _BOOL( StringToInt( str ) );

	if ( strcmp( str, "true", false ) == 0 || strcmp( str, "yes", false ) == 0 || strcmp( str , "on", false ) == 0 || str[0] == '1' )
		return true;

	return false;
}
Sometimes i use words like "true" in my configs, sometimes only "0" and "1". You can use same method if you want.
it's not bad but what would I return if there's a failure? I guess I could have it pass something like a reference to a bool and the method itself returns an int.

Another thing is that your method just checks if the word is "true" or something synonymous and returns false otherwise, which means someone could just put "peanut butter" as a value and trying to make that as a bool would return a value of false lol.

Treating a string value as a bool would require the value of the key to actually represent something that makes sense as a boolean value as opposed to having specific words being able to be treated as a boolean value while everything else is just assumed boolean false.
__________________
nergal is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:51.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode