SA-MP Forums Archive
[help] Need a define that returns a formatted string - 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)
+--- Thread: [help] Need a define that returns a formatted string (/showthread.php?tid=340637)



[help] Need a define that returns a formatted string - DeathTone - 08.05.2012

#define FString(%0,%1) do{new _fstring[128]; format(_fstring, 128, %0, %1); return _fstring;} while(FALSE)
or
#define FString(%0,%1) do{new _fstring[128]; format(_fstring, 128, %0, %1);} while(FALSE)
then using _fstring and it just said undefined.

I then tried
#define FString(%3,%0,%1) do{new %3[128]; format(%3, 128, %0, %1); } while(FALSE)
Still wouldn't work, does anyone have a define that can easily format a string and return it, i'm trying to make formatting as easy as possible without having to declare new strings ect.


Re: [help] Need a define that returns a formatted string - MP2 - 08.05.2012

pawn Код:
#define PLUR(%0,%1,%2) (%0),((%0) == 1)?((#%1)):((#%2))
Usage:
pawn Код:
format(string, sizeof(string), "%i %s", PLUR(var, "instance", "instances");
for example
pawn Код:
PLUR(pKills[playerid], "kill", "kills");
Look at the macro code and take it from it. I don't understand it.


Re: [help] Need a define that returns a formatted string - 2KY - 08.05.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
What exactly are you trying to do? That code just calls format so there's no need for a macro.
I'm assuming he wants something like SendFormattedMessage, which he can just do something like:

pawn Код:
SendFormattedMessage( playerid, -1, "%s has %d apples!", p_Name, p_Apples [ playerid ] );
If I remember correctly, I asked this question on an older account of mine, and you (******) wrote a library for it. I don't remember what you called it however.


Re: [help] Need a define that returns a formatted string - 2KY - 08.05.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
y_va (for "Variable Arguments" as it wraps two va functions). In retrospect, maybe not the most descriptive name ever...
Eh, it's not too bad. You can figure out what it does, lol.


Re: [help] Need a define that returns a formatted string - DeathTone - 08.05.2012

I just want something easier than having to format a string each time, instead of

new string[128];
format(string, 128, "%s %d %f", mystring, myvar, myfloat);

It would be simpler to just use something like FS("%s %d %f", mystring, myvar, myfloat);

I'm not gonna use this for sending formatted client messages (already got something for that)