AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   better way to declare CVARs (https://forums.alliedmods.net/showthread.php?t=162067)

gamer99 07-14-2011 11:27

better way to declare CVARs
 
Hi ,

Suppose I have a CVAR

g_dTest = register_cvar("test","1")

Now g_dTest I have declared globaly . Suppose I need to use the value of
the cvar within one function with is being called every 1 sec. So i wrote

new iTest = get_pcvar_num(g_dTest) inside the function .
But with this get_pcvar_num is being called also every time .
Can we do like
1)declaring iTest globally and then calling one function which will set the value of iTest globally ?

Is there any disadvantage in this ?or what is the better way of declaring one cvar ?

Arkshine 07-14-2011 11:35

Re: better way to declare CVARs
 
You could cache the value :

- Into a global var, like each new round or something. The cons is your var won't be updated in real-time.
- Using my awesome module Cvar Utilities, you can hook a value change of a cvar and caching the value into a global var. It will updated in real-time.

fysiks 07-14-2011 13:50

Re: better way to declare CVARs
 
I don't know of any cvar that needs to be real-time updated. 99% of cvars could be cached on init and nobody would know the difference.

Arkshine 07-14-2011 13:58

Re: better way to declare CVARs
 
You're wrong but it's ok.

fysiks 07-14-2011 14:06

Re: better way to declare CVARs
 
Quote:

Originally Posted by Arkshine (Post 1510702)
You're wrong but it's ok.

Ok, maybe 99% is too high, maybe if I exclude cvars that enable/disable things (which really aren't being used as cvars anyways). Thanks for being ok ;).

Arkshine 07-14-2011 14:08

Re: better way to declare CVARs
 
No problem. You're welcome. I'm glad you're aware to not know all.

gamer99 07-14-2011 14:34

Re: better way to declare CVARs
 
Quote:

Originally Posted by Arkshine (Post 1510609)
You could cache the value :

- Into a global var, like each new round or something. The cons is your var won't be updated in real-time.
- Using my awesome module Cvar Utilities, you can hook a value change of a cvar and caching the value into a global var. It will updated in real-time.

wonderful module but i don't want any extra module :D


Quote:

I don't know of any cvar that needs to be real-time updated. 99% of cvars could be cached on init and nobody would know the difference.
init is a good idea :D...lemme try that :D

gamer99 07-14-2011 14:46

Re: better way to declare CVARs
 
init is not working ... i am checking is a client prethink ... And declaring the cvar as global ....

I don wanna any extra module .... better I will check every time in prethink

jimaway 07-14-2011 14:59

Re: better way to declare CVARs
 
Quote:

Originally Posted by gamer99 (Post 1510605)
Hi ,

Suppose I have a CVAR

g_dTest = register_cvar("test","1")

Now g_dTest I have declared globaly . Suppose I need to use the value of
the cvar within one function with is being called every 1 sec. So i wrote

new iTest = get_pcvar_num(g_dTest) inside the function .
But with this get_pcvar_num is being called also every time .

Can we do like
1)declaring iTest globally and then calling one function which will set the value of iTest globally ?

Is there any disadvantage in this ?or what is the better way of declaring one cvar ?

Quote:

Originally Posted by gamer99 (Post 1510723)
init is not working ... i am checking is a client prethink ... And declaring the cvar as global ....

I don wanna any extra module .... better I will check every time in prethink

wait what? originally you were concerned that get_pcvar_num gets called every second, so instead you will call it at EVERY frame

gamer99 07-14-2011 15:12

Re: better way to declare CVARs
 
sry for the one second confudion .. the should be one frame ..:D ..

I was trying to avoid that calling every frame ...:)


All times are GMT -4. The time now is 01:07.

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