[help] Need a define that returns a formatted string
#1

#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.
Reply
#2

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.
Reply
#3

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.
Reply
#4

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.
Reply
#5

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)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)