AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Macros with optional arguments (https://forums.alliedmods.net/showthread.php?t=153038)

PRoSToTeM@ 03-17-2011 17:34

Macros with optional arguments
 
Can I make macros with optional arguments?

Emp` 03-18-2011 13:03

Re: Macros with optional arguments
 
Give an example of what you are trying to do.

nikhilgupta345 03-18-2011 23:20

Re: Macros with optional arguments
 
I guess he means like get_systime or something like that, how you can put an optional offset. Or set a default value.

wrecked_ 03-19-2011 16:23

Re: Macros with optional arguments
 
After a quick look at the Pawn Language Guide, I was not able to find anything indicating this is possible with Pawn.

You're better off just using a function.

Emp` 03-19-2011 16:44

Re: Macros with optional arguments
 
You have to think outside the box. %1 can be more than one argument.

For Example:
Code:

stock nfv_get_data(const filename[], const key[], name[], data[]="", len=0, const identifier=';', const key_tell_start=0, &key_tell_find=0, const name_tell_start=0, &name_tell_find=0, key_copy[]="", const key_len=0, name_copy[]="", const name_len=0)
#define player_get_data(%1,%2) nfv_get_data(nfv_player_file(%1),%2)


PRoSToTeM@ 03-25-2011 07:48

Re: Macros with optional arguments
 
I tell about this
PHP Code:

#define set_user_money(%1,%2,%3) cs_set_user_money(%1,%2,%3)
// How not to use 3rd argument in this code
set_user_money(id16000


Emp` 03-25-2011 15:43

Re: Macros with optional arguments
 
Code:

#define set_user_money(%1) cs_set_user_money(%1)
You don't need to do it for each argument.

You could also just do this:
Code:

#define set_user_money cs_set_user_money


All times are GMT -4. The time now is 14:41.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.