Raised This Month: $32 Target: $400
 8% 

define question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 03-29-2015 , 13:31   define question
Reply With Quote #1

Will it somehow affect plugin if there's one or a lot of defines like that?

PHP Code:
#define    SetHealth(%1)        set_user_health(%1) 

Last edited by ~Ice*shOt; 03-29-2015 at 13:33.
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
Obada
Senior Member
Join Date: Dec 2014
Location: Abu Dhabi
Old 03-29-2015 , 13:53   Re: define question
Reply With Quote #2

I don't think so.
Obada is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 03-29-2015 , 13:56   Re: define question
Reply With Quote #3

So there will be exactly the same if I use

PHP Code:
set_user_health(id
or I'll define

PHP Code:
#define    SetHealth(%1)        set_user_health(%1) 
and use SetHealth(id)

Last edited by ~Ice*shOt; 03-29-2015 at 13:58.
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-29-2015 , 14:32   Re: define question
Reply With Quote #4

Quote:
Originally Posted by ~Ice*shOt View Post
Will it somehow affect plugin if there's one or a lot of defines like that?

PHP Code:
#define    SetHealth(%1)        set_user_health(%1) 
No. But, you've done it wrong for this function, set_user_health() requires two arguments.\

It would probably help if you know what a #define actually does. It replaces the defined 'thing' with it's definition at compile time. So, after you compile it, the code will no longer contain "SetHealth()", it will contain only it's definition "set_user_health()".
__________________

Last edited by fysiks; 03-29-2015 at 14:34.
fysiks is online now
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 03-29-2015 , 16:51   Re: define question
Reply With Quote #5

So it doesn't make sense I use my defined function or original, thanks.
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-02-2015 , 19:24   Re: define question
Reply With Quote #6

Quote:
Originally Posted by ~Ice*shOt View Post
So it doesn't make sense I use my defined function or original, thanks.
They are useful for not having to re-write things over and over again. You still need to call the macro, but you can avoid repeating parts of it that are constant.
PHP Code:
//ie. instead of 
set_user_healthid 100 )

//you would just do 
#define SetHealth(%1)   set_user_health(%1, 100) 

//Then in code, you can leave out the 100 part and just do 
SetHealthid 
At compile, as fysiks said, every instance of SetHealth(val ) is replaced with set_user_health( val , 100 ). There's no damage or benefit on performance.

Also, for things like this it makes it a lot easier to use the macro instead of writing it out multiple times:
PHP Code:
#define SetBit(%1)   (g_Bits |= (1<<%1))
#define ClearBit(%1)   (g_Bits &= ~(1<<%1)) 
__________________
Bugsy is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 04-03-2015 , 13:22   Re: define question
Reply With Quote #7

Thanks!
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:25.


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