SA-MP Forums Archive
Using #define Instead of Stock here - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Using #define Instead of Stock here (/showthread.php?tid=439072)



Using #define Instead of Stock here - Swimor - 23.05.2013

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!


Re: Using #define Instead of Stock here - Vince - 23.05.2013

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.


Re: Using #define Instead of Stock here - Swimor - 24.05.2013

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


Re: Using #define Instead of Stock here - Bakr - 24.05.2013

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

Your signature is also incorrect.


Re: Using #define Instead of Stock here - 2KY - 24.05.2013

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.


Respuesta: Using #define Instead of Stock here - Carloselunico - 24.05.2013

?
:
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


Re: Using #define Instead of Stock here - Bakr - 24.05.2013

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


Respuesta: Using #define Instead of Stock here - Carloselunico - 25.05.2013

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;
}



Re: Using #define Instead of Stock here - Bakr - 25.05.2013

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


Re: Respuesta: Using #define Instead of Stock here - Pottus - 25.05.2013

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?