Page 1 of 1

To be a listener to a specific CVAR

Posted: Tue Feb 14, 2017 2:25 pm
by RainMan14
Hello,

I want to be a listener to a specific CVAR. If its value is changed i want to know it. I can check its value every update but it costs much. How can i be a listener to a specific CVAR? Thanks

RainMan14

Re: To be a listener to a specific CVAR

Posted: Tue Feb 14, 2017 2:35 pm
by Cry-Jan
CVars have support for a callback function that is called when the CVar changes. All you need to do is to register the CVar with a *_CB macro (e.g. REGISTER_CVAR_CB instead of REGISTER_CVAR) and pass in the function that should be called when the value changes.

Re: To be a listener to a specific CVAR

Posted: Tue Feb 14, 2017 2:52 pm
by RainMan14
Thank you @cry-jan.

I missed the *_CB functions. As far as I see, it takes just one function. I can solve my problem with a wrapper but you may want to changed it with std::initializer_list. Then programmers can give more than one function. Just my opinion, maybe there is some problems for that.

RainMan14

Re: To be a listener to a specific CVAR

Posted: Wed Feb 15, 2017 1:55 pm
by Cry-Jan
Allowing multiple callbacks per CVar would probably require a non-trivial refactoring and I can't remember ever having a pressing need for this feature. Anyway, if you need multiple callbacks you can always create an additional functions that calls all the others and then register that 'master-callback' on the CVar.