Raised This Month: $ Target: $400
 0% 

better way to declare CVARs


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gamer99
Senior Member
Join Date: Jul 2011
Old 07-14-2011 , 11:27   better way to declare CVARs
Reply With Quote #1

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 ?
gamer99 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-14-2011 , 11:35   Re: better way to declare CVARs
Reply With Quote #2

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.
__________________
Arkshine is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-14-2011 , 13:50   Re: better way to declare CVARs
Reply With Quote #3

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.
__________________
fysiks is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 07-14-2011 , 14:34   Re: better way to declare CVARs
Reply With Quote #4

Quote:
Originally Posted by Arkshine View Post
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


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 ...lemme try that
gamer99 is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 07-14-2011 , 14:46   Re: better way to declare CVARs
Reply With Quote #5

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
gamer99 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-14-2011 , 13:58   Re: better way to declare CVARs
Reply With Quote #6

You're wrong but it's ok.
__________________
Arkshine is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-14-2011 , 14:06   Re: better way to declare CVARs
Reply With Quote #7

Quote:
Originally Posted by Arkshine View Post
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 ;).
__________________
fysiks is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-14-2011 , 14:08   Re: better way to declare CVARs
Reply With Quote #8

No problem. You're welcome. I'm glad you're aware to not know all.
__________________
Arkshine is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 07-14-2011 , 14:59   Re: better way to declare CVARs
Reply With Quote #9

Quote:
Originally Posted by gamer99 View Post
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 View Post
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
jimaway is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 07-14-2011 , 15:12   Re: better way to declare CVARs
Reply With Quote #10

sry for the one second confudion .. the should be one frame .. ..

I was trying to avoid that calling every frame ...
gamer99 is offline
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 01:07.


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