Using #define Instead of Stock here
#1

Using #define Instead of Stock here

Hello,

I have little stock to get the player file,
Код:
stock GetPlayerFile(playerid) {
    new file[64];
    format(file, sizeof(file), "players/%s.ini", GetName(playerid));
    return file;
}
I want to use this code instead, Is it possible? here the code:
Код:
#define GetPlayerFile(%0) "players/"#GetName(%0)".ini"
Thanks,
Rafael!
Reply
#2

No. That will compile as (assuming playerid is 0):
pawn Код:
"players/""GetName("0)".ini"
Just stick with functions, okay? I've never understood the need for people to squeeze all and everything into macros.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
No. That will compile as (assuming playerid is 0):
pawn Код:
"players/""GetName("0)".ini"
Just stick with functions, okay? I've never understood the need for people to squeeze all and everything into macros.
But this
Код:
#define GetPlayerFile(%0) "players/"#%0".INI"
Will compile as
Код:
GetPlayerFile("players/""0".ini");
And will work...
Reply
#4

No, it won't. Read the "Pawn Pre-Processor" thread by ******.

Your signature is also incorrect.
Reply
#5

Quote:

I have little stock to get the player file,

So you need to squeeze a 5 line function into a 1 line macro, saving bytes of space? There's no point. Just stick with the functions, a lot more simple.
Reply
#6

?
:
pawn Код:
#define GetPFile(%0,%1); new %0[64]; \
format(%0, sizeof(%0), "players/%s.ini", GetName(%1));
Use:
Quote:

GetPFile(File,playerid);
//-----------------------
File = "players/Rafael.ini"
-------------------------

Or Array Global:


pawn Код:
new ArrayGlobal[256];
#define GetFile(%0) \
((format(ArrayGlobal, sizeof(ArrayGlobal), "players/%s.ini", GetName(%0)), ArrayGlobal))
Use:
Quote:

if(fExists(GetFile(playerid))
{

GetFile(playerid) = "players/Rafael.ini"

Sorry for mi english, I'm Spanish
Reply
#7

That would compile as
pawn Код:
if(fexist(((format(ArrayGlobal, sizeof(ArrayGlobal), "players/%s.ini", GetName(playerid)), Array))
Again, incorrect.
Reply
#8

no? comes to criticize but do not contribute anything.
pawn Код:
new ArrayGlobal[256];
#define GetFile(%0) \
((format(ArrayGlobal, sizeof(ArrayGlobal), "players/%s.ini", Name(%0)), ArrayGlobal))
pawn Код:
stock Name(p)
{
new aux[MAX_PLAYER_NAME];
GetPlayerName(p, aux, sizeof(aux));
return aux;
}

----------------------------------------------------
Look:


pawn Код:
if(!strcmp("/mifile", cmdtext, true))
{
SendClientMessage(playerid, -1, GetFile(playerid)); // show file name text players/carlos.ini
if(fexist(GetFile(playerid))) return SendClientMessage(playerid, -1, #ifexists); // if exist
else SendClientMessage(playerid, -1, #Noexists); // if no exists
return 1;
}
Reply
#9

You are right, it will work. That doesn't exclude it from being a very poor use case though.
Reply
#10

Quote:
Originally Posted by Carloselunico
Посмотреть сообщение
no? comes to criticize but do not contribute anything.
pawn Код:
new ArrayGlobal[256];
#define GetFile(%0) \
((format(ArrayGlobal, sizeof(ArrayGlobal), "players/%s.ini", Name(%0)), ArrayGlobal))
pawn Код:
stock Name(p)
{
new aux[MAX_PLAYER_NAME];
GetPlayerName(p, aux, sizeof(aux));
return aux;
}

----------------------------------------------------
Look:


pawn Код:
if(!strcmp("/mifile", cmdtext, true))
{
SendClientMessage(playerid, -1, GetFile(playerid)); // show file name text players/carlos.ini
if(fexist(GetFile(playerid))) return SendClientMessage(playerid, -1, #ifexists); // if exist
else SendClientMessage(playerid, -1, #Noexists); // if no exists
return 1;
}
No need for a 256 array size what is the purpose for that?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)