Forum

[Engine] DP_CON_SET

Post tutorials on how to do certain tasks within game or engine code here.

Moderator: InsideQC Admins

[Engine] DP_CON_SET

Postby Spike » Thu Jul 29, 2010 11:20 pm

quick easy one:

cvar.c (or cmd.c, whereever really)
Code: Select all
void Cvar_Set_f(void)
{
   char *cvarname;
   char *cvarvalue;
   cvar_t *var;

   cvarname = Cmd_Argv(1);
   cvarvalue = Cmd_Argv(2);

   var = Cvar_FindVar(cvarname);
   if (!var)
   {
      if (Cmd_Exists(cvarname))
      {
         Con_Printf("%s exists as a command\n", cvarname);
         return;
      }
      var = malloc(sizeof(*var));
      if (!var)
         return;
      memset(var, 0, sizeof(*var));
      var->name = strdup(cvarname);
      var->string = "";
      Cvar_RegisterVariable(var);
   }

   Cvar_Set(cvarname, cvarvalue);
}

(try and find a cvar, if it doesn't exist, make sure its not already a command, malloc space for it, register it with an empty default value, and then set it to the argument requested)

cvar.h, add the following somewhere.
Code: Select all
void Cvar_Set_f(void);


cmd.c, Cmd_Init, add
Code: Select all
   Cmd_AddCommand ("set", Cvar_Set_f);

somewhere.


Now mods that use your engine don't have to use inane meaninglessly named cvars called 'temp1' for instance, but can instead use sane names like 'g_maxbots'. Because its slightly more sane.

Have fun... :P
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Return to Programming Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest