Placeholder for boolean data type in format-function
#1

Hey. One simple question:
Is there an easy way to add boolean variables into a string, like:
pawn Код:
new string[25], bool:TrueOrFalse=true;
format(string, sizeof(string), "The statement is %boolean", TrueOrFalse);
'%boolean' should be a pseudo placeholder for boolean variables. Now here is my question: Is there a placeholder that does something similar? And if yes, what is its' name/character?
If not, is there an easy way of adding true/false to a string, without using a mass of if-statements?

#Edit#:

Alright, I made a sollution for this on my own now:
pawn Код:
strbool(string[], bool:var, maxlength=sizeof(string))
{
    switch(var)
    {
        case true: return strcat(string, "true", maxlength);
        case false: return strcat(string, "false", maxlength);
    }
    return -1;
}
It works like strcat, just with a boolean as second value, instead of an string. maxlength is optional.

If there is still another way, please let me know.

Thank you.
Reply
#2

I don't know if theres another better way available but i wrote a quick function that might work. (not tested)
pawn Код:
ReturnBoolString(value)
{
    if(value > 0)
    {
        new str[5] = {"true"};
        return str;
    }
    else
    {
        new str[6] = {"false"};
        return str;
    }
}
You could use that in format with %s specifier.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)