Placeholder for boolean data type in format-function - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Placeholder for boolean data type in format-function (
/showthread.php?tid=202538)
Placeholder for boolean data type in format-function -
DeathOnaStick - 24.12.2010
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.
Re: Placeholder for boolean data type in format-function -
iggy1 - 24.12.2010
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.