AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   PCvars? (https://forums.alliedmods.net/showthread.php?t=46999)

Drak 11-07-2006 00:19

PCvars?
 
Iv been hearing a lot about 'pcvars'. What exactly is it? Is it better then just normal CVARS?

Emp` 11-07-2006 00:33

Re: PCvars?
 
they work a lot faster than normal get_cvar_* functions because they use pointers (I'm guessing, I know a little bit of C++ and I think I see why using pointers would help here, anyway...). You have to register them to a global variable (unless your only using it once). Heres some example code...
Code:

//i like to make it the same name as the actual cvar
new sv_my_cvar
public plugin_init()
{
    sv_my_cvar = register_cvar("sv_my_cvar","0")
}
my_function()
{
    client_print(0, print_chat, "wow, my cvar = %d", get_pcvar_num(sv_my_cvar))
}

*note that there is no set_pcvar_string
}

Drak 11-07-2006 00:55

Re: PCvars?
 
So, pretty much in any case, it's always best to use them?

MaximusBrood 11-07-2006 02:04

Re: PCvars?
 
Yeah, unless you want to support versions of AMX Mod X that don't support pcvars :wink:

The Specialist 11-07-2006 03:44

Re: PCvars?
 
a pcvar is basicly amxmodx's verrsion of a pointer . hooking a varaible directly to cvars . the only time you need to use them is if you use a get_cvar_num("whatever") more then once. if you only use the cvars once in a script theres no need to make a varaible to handle it . becasue everytime a varaible is declared , memory is alocated to handle the variable. so if you use the same cvar more then once , you can use a "pointer" to get and find the varaibles easyier . :up:

teame06 11-07-2006 09:14

Re: PCvars?
 
Quote:

Originally Posted by The Specialist (Post 400732)
a pcvar is basicly amxmodx's verrsion of a pointer . hooking a varaible directly to cvars . the only time you need to use them is if you use a get_cvar_num("whatever") more then once. if you only use the cvars once in a script theres no need to make a varaible to handle it . becasue everytime a varaible is declared , memory is alocated to handle the variable. so if you use the same cvar more then once , you can use a "pointer" to get and find the varaibles easyier . :up:

Not really. Your sacrificing memory for speed. set/get_pcvar_* is a lot faster than set/get_cvar_*.

Code:
#include <amxmodx> new pHello; public plugin_init() {     register_forward(FM_PlayerPreThink, "_FM_PlayerPreThink");     pHello = register_cvar("Hello", "1"); } public _FM_PlayerPreThink(player) {     if(!get_pcvar_num(pHello)     {     }     return FMRES_IGNORED; }

Even if this was all the code. I would still use pcvar in this situation. It also depends on the situation to. Even though the cvar is only use once in this situation. I would do this even though it only use once in this plugin.

Code:
#include <amxmodx> public plugin_init() { } public plugin_cfg() {     new host[64], db[64], user[64], pass[64];         get_cvar_string("host", host, 63);     get_cvar_string("db", db, 63);     get_cvar_string("user", user, 63);     get_cvar_string("pass", pass, 63);         // Do db connection. }

I would not use pcvar here if your not going to use it more than once. Since this is only start of the plugin. Other than that I would only use normal set/get_cvar_* in plugin_init or plugin_cfg.

MaximusBrood 11-07-2006 11:33

Re: PCvars?
 
teame06, he obviously meant that if you are going to save the cvar in a variable, thus reading it only once, it is not neccessary to use a pcvar.

Zenith77 11-07-2006 12:10

Re: PCvars?
 
Quote:

Originally Posted by MaximusBrood (Post 400831)
teame06, he obviously meant that if you are going to save the cvar in a variable, thus reading it only once, it is not neccessary to use a pcvar.

There really is no necessary reason, it's just better. Lately I've seen a lot of beginers to intermidiate scripters worrying about code effiencecy; you don't need to concern yourself with this unless/until you know 100% about what's going on with your code and/or if a plugin is extremely CPU intensive. It's good to have good, clean, efficent code; it's just that some people go over board with it.

Quote:

Originally Posted by The Specialist (Post 400732)
a pcvar is basicly amxmodx's verrsion of a pointer . hooking a varaible directly to cvars . the only time you need to use them is if you use a get_cvar_num("whatever") more then once. if you only use the cvars once in a script theres no need to make a varaible to handle it . becasue everytime a varaible is declared , memory is alocated to handle the variable. so if you use the same cvar more then once , you can use a "pointer" to get and find the varaibles easyier . :up:

Bad/invalid description, on many levels.

MaximusBrood 11-07-2006 12:22

Re: PCvars?
 
Quote:

Originally Posted by Zenith77 (Post 400839)
Lately I've seen a lot of beginers to intermidiate scripters worrying about code effiencecy; you don't need to concern yourself with this unless/until you know 100% about what's going on with your code and/or if a plugin is extremely CPU intensive.

Thats very far from the truth.

The Specialist 11-07-2006 16:44

Re: PCvars?
 
zenith doesnt care he just likes to argue. wether hes wrong or not :wink:
team06 on the other hand is good at explaining things , and ill believe team06 in this case .


All times are GMT -4. The time now is 06:57.

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