#define VACheck(%0,%1,%2)\ do{\ if(PlayerInfo[(%0)][pVip] < (%1) || PlayerInfo[(%0)][Level] < (%2)){\ new Str[128];\ format(Str, 128, "~r~~h~ERROR!~n~~w~You need to be V.I.P level ~y~~h~%d ~w~ or admin level ~y~~h~%d ~w~to use this command!", (%1), (%2));\ return GameTextForPlayer((%0), Str, 3000, 4);\ }\ }\ while(False)
CMD:god( playerid, params[ ] ) { VACheck( playerid, 4, 4 ); SendClientMessage( playerid, 0xFFFFF, "Testing" ); return 1; }
Originally Posted by ******
So why use macros instead of functions (or why use functions instead of macros)? Macros replace text - so wherever you put the macro, there will your replacement go. If you have a macro in your code 100 times, that code will get generated 100 times. On the other hand if you have a function in your code 100 times, its code will only appear once with 100 calls to it. The latter is probably preferable if you have a lot of code - large chunks of code appearing 100 times will make a very large AMX file! Macros tend to be used for very small bits of code - calling a function takes time, so if you have very tiny code it's not really worth the effort of calling a function, but this is not a rule! If you used a function instead of the macros above, the code compiled would look like:
|