Page 1 of 1

Strange Convar.set_int behavior

Posted: Mon Jun 04, 2018 6:18 pm
by Kami
Hey guys,

I'm using this code to initialize server variables from a txt file:

Syntax: Select all

import os
from cvars import ConVar

def get_addon_path():
path = os.path.dirname(os.path.abspath(__file__))
return path

path = get_addon_path()+"/svar/svar.txt"
file = open(path)
lines = [line.rstrip('\n') for line in file]

for line in lines:
if not line.startswith('//'):
if line != "":
ConVar(line).set_int(0)
file.close()


The problem is that ConVar(line).set_int(0) will not set the variable to 0 but to an empty string, which then leads to problems when I try to do math on them.
When I use

Syntax: Select all

ConVar(line).set_int(1)
ConVar(line).set_int(0)


it works like it's intended but does not seem like the way it should be. I think this might be a bug.

Thank you :)

Re: Strange Convar.set_int behavior

Posted: Fri Jul 20, 2018 4:37 am
by BackRaw
Maybe try

Syntax: Select all

from cvars import cvar

cvar.find_var(line).set_int(0)

Re: Strange Convar.set_int behavior

Posted: Sat Jul 21, 2018 11:52 pm
by satoon101
I'm not entirely sure what you are attempting to do, but I imagine it has to do with WCS and using ES-style console commands. You might try using set_string('0') to see if that fixes your issue.