SA-MP Forums Archive
#define Problem - 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: #define Problem (/showthread.php?tid=559861)



#define Problem - yellow - 25.01.2015

Got this code:
Code:
new fq=false;
#define SendError(%0,%1)\
do{new _str[128];format(_str,sizeof(_str)," ERROR: {FFFFFF}%1");SendClientMessage(%0,Error,_str);}while(fq)
Code:
SendError(playerid,"You are not allowed to ...");
works fine, but
Code:
if(!var[playerid])return SendError(playerid,"You are not allowed...");
doesnt work:
Code:
error 029: invalid expression, assumed zero
 warning 217: loose indentation
 error 036: empty statement
 warning 217: loose indentation



Re: #define Problem - zaibaslr2 - 25.01.2015

pawn Code:
#define SendError(%0,%1)\
SendClientMessage(%0,Error,%1)
I don't know why you need such complicated define.
Use this instead, this should work.


AW: #define Problem - yellow - 25.01.2015

I'm sure that your code would work. But i don't want it like that.

I don't always want to add " ERROR: {FFFFFF}" to my string. Therefor i wrote the #define.


Re: #define Problem - zaibaslr2 - 25.01.2015

pawn Code:
#define SendError(%0,%1)\
new fstr[128]; format(fstr,sizeof(fstr),"ERROR:{FFFFFF}%s",%1);\
SendClientMessage(%0,Error,fstr)
Would this work?


AW: #define Problem - yellow - 25.01.2015

Wouldn't work; had nearly the same before.


Re: #define Problem - zaibaslr2 - 25.01.2015

pawn Code:
if(!var[playerid])
(
SendError(...);
return 1;
)
Does this give any errors?


AW: #define Problem - yellow - 25.01.2015

Nope, thanks. But why?


Re: #define Problem - zaibaslr2 - 25.01.2015

pawn Code:
new fq=false;
#define SendError(%0,%1)\ do{new _str[128];format(_str,sizeof(_str)," ERROR: {FFFFFF}%1");SendClientMessage(%0,Error,_str); return 1;}while(fq)
Try this define and try using
pawn Code:
if(!var[playerid]) return SendError(...);



AW: #define Problem - yellow - 25.01.2015

No, still the same errors. But thanks


Re: #define Problem - zaibaslr2 - 25.01.2015

pawn Code:
define SendError(%0,%1)\
new fstr[128]; format(fstr,sizeof(fstr),"ERROR:{FFFFFF}%s",%1);\
return SendClientMessage(%0,Error,fstr)
Just use this define instead.


Re: #define Problem - PowerPC603 - 25.01.2015

Just create a function for it, it's more efficient and easier to change.

When you use a function many times, your amx will only hold a call to the function.
When you use a define, your amx will hold many copies of the same code and will eventually be much larger.


AW: #define Problem - yellow - 25.01.2015

Would not work. As is said, there would be the Error "undefinied symbol "fstr" or sth. like that

/edit:

Yep, but why doesn't the define work with "return" ?


Re: #define Problem - zaibaslr2 - 25.01.2015

Does my define work?
when you are using return Function(); the script returns function's return value, but the define does not return anything in your case.


AW: #define Problem - yellow - 25.01.2015

Nope, your's didn't work.
I created a function.
Thanks 2 you 2