From: terencehill Date: Wed, 25 Apr 2012 21:47:41 +0000 (+0200) Subject: Error out if a cvar doesn't exist in cvar_settemp_restore and in cvar_settemp avoidin... X-Git-Tag: xonotic-v0.7.0~194^2~3 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=43bb6b7fd1b328e8652d1023082d90860add8b8a;p=xonotic%2Fxonotic-data.pk3dir.git Error out if a cvar doesn't exist in cvar_settemp_restore and in cvar_settemp avoiding to spawn a new entity with meaningless info --- diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 582777647..94e1e6461 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -859,30 +859,36 @@ float cvar_settemp(string tmp_cvar, string tmp_value) { float created_saved_value; entity e; - + if not(tmp_cvar || tmp_value) { dprint("Error: Invalid usage of cvar_settemp(string, string); !\n"); return FALSE; } - + + if(!cvar_type(tmp_cvar)) + { + print(sprintf("Error: cvar %s doesn't exist!\n", tmp_cvar)); + return FALSE; + } + for(e = world; (e = find(e, classname, "saved_cvar_value")); ) if(e.netname == tmp_cvar) goto saved; // skip creation - + // creating a new entity to keep track of this cvar e = spawn(); e.classname = "saved_cvar_value"; e.netname = strzone(tmp_cvar); e.message = strzone(cvar_string(tmp_cvar)); created_saved_value = TRUE; - + // an entity for this cvar already exists :saved - + // update the cvar to the value given cvar_set(tmp_cvar, tmp_value); - + return created_saved_value; } @@ -890,12 +896,17 @@ float cvar_settemp_restore() { float i; entity e; - while((e = find(world, classname, "saved_cvar_value"))) + while((e = find(e, classname, "saved_cvar_value"))) { - cvar_set(e.netname, e.message); - remove(e); + if(cvar_type(e.netname)) + { + cvar_set(e.netname, e.message); + remove(e); + } + else + print(sprintf("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.\n", e.netname)); } - + return i; }