Help with macro?
#1

Is this possible?

pawn Код:
#define GetName(%1) new name[MAX_PLAYER_NAME]; GetPlayerName(%1, name, MAX_PLAYER_NAME); return name
And in use

GetName(playerid);

I get this errors

pawn Код:
C:\Users\ExtremePower\Desktop\Lve\gamemodes\adrenaline.pwn(1897) : error 029: invalid expression, assumed zero
C:\Users\ExtremePower\Desktop\Lve\gamemodes\adrenaline.pwn(1897) : error 017: undefined symbol "name"
C:\Users\ExtremePower\Desktop\Lve\gamemodes\adrenaline.pwn(1897) : warning 215: expression has no effect
C:\Users\ExtremePower\Desktop\Lve\gamemodes\adrenaline.pwn(1897) : error 001: expected token: ";", but found "]"
C:\Users\ExtremePower\Desktop\Lve\gamemodes\adrenaline.pwn(1897) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
can someone fix macro ?
Reply
#2

pawn Код:
#define GetName(%1)\
new name[25];\
GetPlayerName((%1),name,25);\
return name
Reply
#3

That way i know too, but i was asked is it possible to make all in one line, mut never mine tnx anyway
Reply
#4

A macro replaces code by something "easier".

For example, if you take your macro:

pawn Код:
#define GetName(%1) new name[MAX_PLAYER_NAME]; GetPlayerName(%1, name, MAX_PLAYER_NAME); return name
Should you use it for example:

pawn Код:
format(string, sizeof string, "Hey %s", GetName(playerid));
It would compile as:

pawn Код:
format(string, sizeof string, "Hey %s", new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, MAX_PLAYER_NAME); return name);
Now obviously that'll cause the compiler to error.

So here's what the problem is: A macro replaces a piece of code. You must use a function to retrieve a variable.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)