Which code is better?
#1

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

%0 and %1 aren't used in the first one?
Reply
#3

There is no any problem with the code, I just ask if to use global var or way 1.
Reply
#4

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

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?
Reply
#6

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

BTW the max client message length is 144, not 128 (or 143? not sure).
Reply
#8

Max Client Message is 128.
Reply
#9

128 + player name i guess makes 144

beh
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)