]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Error out if a cvar doesn't exist in cvar_settemp_restore and in cvar_settemp avoidin...
authorterencehill <piuntn@gmail.com>
Wed, 25 Apr 2012 21:47:41 +0000 (23:47 +0200)
committerterencehill <piuntn@gmail.com>
Wed, 25 Apr 2012 22:19:18 +0000 (00:19 +0200)
qcsrc/common/util.qc

index 582777647c9fcd2e2798baa4c695ecea269d3969..94e1e64611760d3cafead8b8dccf4508b8a98ae0 100644 (file)
@@ -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;
 }