Skip to content

Added the ability to add callbacks to ConVar that will be called when ConVar is changed. #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Changed to check if ConVar is a valid ConVar.
  • Loading branch information
CookStar committed Oct 4, 2021
commit 94e24badfcd2272e854cf010b1c656e15eac8b7f
15 changes: 8 additions & 7 deletions addons/source-python/packages/source-python/cvars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ def __init__(self, *convars):

_convars = []
for convar in convars:
if not isinstance(convar, (str, ConVar)):
if isinstance(convar, str):
convar_name = convar
elif isinstance(convar, ConVar):
convar_name = convar.name
else:
raise ValueError('Given convar is not ConVar or ConVar name.')

elif isinstance(convar, str):
convar_name = convar
convar = cvar.find_var(convar_name)
if convar is None:
raise ValueError(
f'"{convar_name}" is not a valid ConVar name.')
convar = cvar.find_var(convar_name)
if convar is None:
raise ValueError(f'"{convar_name}" is not a valid ConVar.')

_convars.append(convar)

Expand Down