AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Defines vs Cvars (https://forums.alliedmods.net/showthread.php?t=112908)

Doc-Holiday 12-22-2009 02:01

Defines vs Cvars
 
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

dFF 12-22-2009 02:30

Re: Defines vs Cvars
 
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)

Arkshine 12-22-2009 02:31

Re: Defines vs Cvars
 
#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.

Doc-Holiday 12-22-2009 03:00

Re: Defines vs Cvars
 
Quote:

Originally Posted by Arkshine (Post 1026502)
#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 (Post 1026501)
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

Arkshine 12-22-2009 05:24

Re: Defines vs Cvars
 
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.

Doc-Holiday 12-22-2009 05:42

Re: Defines vs Cvars
 
Quote:

Originally Posted by Arkshine (Post 1026609)
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.

Arkshine 12-22-2009 05:45

Re: Defines vs Cvars
 
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.

Doc-Holiday 12-22-2009 05:50

Re: Defines vs Cvars
 
Quote:

Originally Posted by Arkshine (Post 1026629)
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.

Arkshine 12-22-2009 05:53

Re: Defines vs Cvars
 
So, use the way you find the more convenient for you.


All times are GMT -4. The time now is 04:15.

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