Inside3D!
     

[Engine] DP_CON_SET

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials
View previous topic :: View next topic  
Author Message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Thu Jul 29, 2010 11:20 pm    Post subject: [Engine] DP_CON_SET Reply with quote

quick easy one:

cvar.c (or cmd.c, whereever really)
Code:

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:

void Cvar_Set_f(void);


cmd.c, Cmd_Init, add
Code:

   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
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group