Strange Convar.set_int behavior

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Kami
Global Moderator
Posts: 143
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Strange Convar.set_int behavior

Postby Kami » Mon Jun 04, 2018 6:18 pm

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 :)
User avatar
BackRaw
Senior Member
Posts: 505
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: Strange Convar.set_int behavior

Postby BackRaw » Fri Jul 20, 2018 4:37 am

Maybe try

Syntax: Select all

from cvars import cvar

cvar.find_var(line).set_int(0)
User avatar
satoon101
Project Leader
Posts: 2578
Joined: Sat Jul 07, 2012 1:59 am

Re: Strange Convar.set_int behavior

Postby satoon101 » Sat Jul 21, 2018 11:52 pm

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.
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 3 guests