To hook or not to hook, that is the question.
Please help a new coder understand the current recommended practice for tracking convar changes in both transitional and methodmap syntax.
In this example we have several different approaches: PHP Code:
Bonus question: what's the optimal method for using cvars to calculate another cvars new value? Exmple: PHP Code:
PG |
Re: To hook or not to hook, that is the question.
It is my understanding that it's now better practise to not hook convar changes. When using the new ConVar methodmap, it apparently caches the values and updates itself.
Im sure a dev will jump in if anything stated is wrong. |
Re: To hook or not to hook, that is the question.
Quote:
PHP Code:
if all of that is int, not convar, then do like this PHP Code:
|
Re: To hook or not to hook, that is the question.
Quote:
|
Re: To hook or not to hook, that is the question.
Quote:
Quote:
PHP Code:
PHP Code:
PG |
Re: To hook or not to hook, that is the question.
Quote:
|
Re: To hook or not to hook, that is the question.
Quote:
PG |
Re: To hook or not to hook, that is the question.
Quote:
If we just want to check the current value of the cvar, we can just call it when we need it (or cache it to a variable if you prefer that). (i.e. bIsOn = g_cvIsOn.BoolValue or bIsOn = GetConVarBool(g_hIsOn)) In this example, we're going to check the initial value of the "mp_gamemode" cvar and then hook it so we can check for the value whenever it changes: PHP Code:
|
Re: To hook or not to hook, that is the question.
Quote:
PHP Code:
|
Re: To hook or not to hook, that is the question.
Quote:
This thread was made in part due to your removing the convar hook and check section from the early version of my plugin, but also because of comments (not necessarily yours) made in other threads which gave the impression that hooking cvars is really not needed except in very specific cases, such as the one you've detailed here and in Ilusion9's example. That revelation was perplexing because of the number of plugins from very competent authors that include large cvar hook sections. For me, understanding why something is done is as important as learning how it is done. I'm not comfortable applying practices or using code if I don't understand the "why" behind it. Your above example and explanation has helped my understanding of when to hook or not to hook cvars and why. Thanks again for your help and if the need arises, I will definitely contact you to discuss this topic further. Kind regards, Patriot |
All times are GMT -4. The time now is 01:18. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.