Raised This Month: $ Target: $400
 0% 

Defines vs Cvars


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 12-22-2009 , 02:01   Defines vs Cvars
Reply With Quote #1

Got a quick question for you folks..

Is it faster and more efficient to use Defines or pcvars?

Pcvar Examples:
PHP Code:
new hpmax
hpmax 
register_cvar("amx_mhp""200")
......
hpm get_pcvar_num(hpmax);

if(
curhp hpm)
{
      
//do stuff

Define Example:
PHP Code:
#define MAX_HP 200
.....
if(
curhp MAX_HP)
{
   
//do stuff

edit: Keep in mine i will have 6 defines for setting health. or 6 pcvars
Doc-Holiday is offline
dFF
sıɹɹoɥɔ ʞɔnu
Join Date: Oct 2009
Old 12-22-2009 , 02:30   Re: Defines vs Cvars
Reply With Quote #2

cvar - can you change when you want (Not to change plugin .sma)

define - you want to change the value you need to modify directly from plugin (.sma)
dFF is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-22-2009 , 02:31   Re: Defines vs Cvars
Reply With Quote #3

#define is faster since the value is replaced at the compilation.

But the question is wrong. You need to use cvar because you want to offer an easy way to customize some aspect of your plugin, not because it's faster/slower than x things.
__________________
Arkshine is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 12-22-2009 , 03:00   Re: Defines vs Cvars
Reply With Quote #4

Quote:
Originally Posted by Arkshine View Post
#define is faster since the value is replaced at the compilation.

But the question is wrong. You need to use cvar because you want to offer an easy way to customize some aspect of your plugin, not because it's faster/slower than x things.
If its more efficient id use the defines its easy to open the sma change the defines and recompile.. exp with all the damn comments i write HAHAHA.


Thanks for the quick replies.

Quote:
Originally Posted by dFF View Post
cvar - can you change when you want (Not to change plugin .sma)

define - you want to change the value you need to modify directly from plugin (.sma)

I know that.... I was asking which is better for the usage of a plugin meaining which is more efficient. it is a large plugin i am working and want to to be efficient
Doc-Holiday is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-22-2009 , 05:24   Re: Defines vs Cvars
Reply With Quote #5

That's not because you use pcvar your plugin will be less "efficient". It's not an optimisation to use #define; the difference would be extremely trivial. It's matter if you want to offer an easy way to change a value or not. You should start to optimize where the gain is really effective.
__________________
Arkshine is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 12-22-2009 , 05:42   Re: Defines vs Cvars
Reply With Quote #6

Quote:
Originally Posted by Arkshine View Post
That's not because you use pcvar your plugin will be less "efficient". It's not an optimisation to use #define; the difference would be extremely trivial. It's matter if you want to offer an easy way to change a value or not. You should start to optimize where the gain is really effective.
Im using pcvars... was just asking.. both are easy to change lol


Just working on the conor method of healing... haha.. so far no good.
Doc-Holiday is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-22-2009 , 05:45   Re: Defines vs Cvars
Reply With Quote #7

Quote:
Im using pcvars... was just asking.. both are easy to change lol
For you. But :

- Can you change the value per map ? No.
- Can you change the value immediately in game ? No.
__________________
Arkshine is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 12-22-2009 , 05:50   Re: Defines vs Cvars
Reply With Quote #8

Quote:
Originally Posted by Arkshine View Post
For you. But :

- Can you change the value per map ? No.
- Can you change the value immediately in game ? No.
ehh thats fine im going with the pcvars lol.. i have 2 defines fm_set_user_no_buy and something else that never get changed.
Doc-Holiday is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-22-2009 , 05:53   Re: Defines vs Cvars
Reply With Quote #9

So, use the way you find the more convenient for you.
__________________
Arkshine is offline
Reply



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 04:15.


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