Which code is better? -
Activest - 26.04.2013
What to do?
One:
PHP код:
#define PMessage(%0,%1,%2,%3,%4,%5) new %2[%3]; format(%2,sizeof(%2),%4,%5); SendClientMessage(%0,%1,%2)
Two:
PHP код:
new message[128]; // Global var
#define PMessage(%0,%1,%2,%3) format(msg,sizeof(msg,%2,%3); SendClientMessage(%0,%1,msg)
By the way, I mean if to do it as global var or in the define.
Re: Which code is better? -
MP2 - 26.04.2013
%0 and %1 aren't used in the first one?
Re: Which code is better? -
Activest - 26.04.2013
There is no any problem with the code, I just ask if to use global var or way 1.
Re: Which code is better? - Emmet_ - 26.04.2013
Quote:
Originally Posted by MP2
%0 and %1 aren't used in the first one?
|
It is used.
pawn Код:
SendClientMessage(%0,%1,%2)
Do it like this:
pawn Код:
new bool:FALSE;
#define PMessage(%0,%1,%2,%3,%4,%5) do { new msg[128]; format(msg, sizeof(msg), %2, %3); SendClientMessage(%0, %1, msg); } while(FALSE)
Re: Which code is better? -
MP2 - 26.04.2013
Oh, I appear to be blind.
What is the purpose of the while loop and 'FALSE'? Isn't that going to create an infinite loop?
Re: Which code is better? -
Activest - 26.04.2013
Quote:
Originally Posted by ******
No, the use of "FALSE" will fail instantly and thus only run once. This is a technique used to mean that the code ends needing a semi-colon and to restrict scope at the same time. However, I'd say that this is probably the best way:
pawn Код:
new gMessageString[128]; #define PMessage(%0,%1,%2) (format(gMessageString, sizeof (gMessageString), %2),SendClientMessage((%0), (%1), gMessageString))
That is all a single expression so can be correctly used wherever a single expression is expected,and still requires a semi-colon.
|
Thank you.
Re: Which code is better? -
MP2 - 26.04.2013
BTW the max client message length is 144, not 128 (or 143? not sure).
Re: Which code is better? -
KiNG3 - 26.04.2013
Max Client Message is 128.
Re: Which code is better? -
mastermax7777 - 27.04.2013
128 + player name i guess makes 144
beh