Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4039402
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:36:23+00:00 2026-05-20T12:36:23+00:00

I would like to implement what I know as a CVAR System, I’m not

  • 0

I would like to implement what I know as a CVAR System, I’m not entirely sure on what the official name of it is (if any).

It’s essentially a system used in some programs and video games, where a user can pull down a console and input a command, such as “variable 500” to set that variable to 500. Instances of this can be found in any Half-Life game, Doom and Quake games, and many more. The general idea seems to be to hide the underlying architecture, but still allow protected access, for instance, one may be able to view the value for, say, gravity, but not change it. Some of these values may also be functions, for instance, a user may be able to input “create ” to create an enemy type at their location, or some other location specified.

Looking through the Half Life 2 SDK, and from what I remember on the GoldSrc SDK, it seems like they at least implemented “flagging” of sorts, where certain commands would only work under certain conditions, such as if another value was set, or if the user has some permission level.

My initial thought was to create a Dictionary, or an object similar to do that, and use that to bind string values to function delegates, as well as keep a “protection” level of sorts, to limit usage of certain commands. However, this seems rather cumbersome, as I believe I would have to go through and add in a new entry manually for each value or function I wanted to implement. I also don’t know if this would give me the control level I’m looking for.

I believe ideally what I would like would be a CVAR System class, as well as a Register function that can take it say, a variable/function delegate, a string to access it, and whatever protection level I need. This way I can add what I need as I see them, so everything is still in it’s related classes and files.

I’m really just looking for some ideas here, so my questions are:

  • Has anyone ever done something like this before, and if so, how?
  • Would my implementation work? (Theoretically, if not, can you think of a better way?)
  • If someone is more knowledgeable with how one of the previously mentioned titles does it, can you elaborate on that a bit? It seems to be hard to find documentation on them.

I’m not really looking for specific code, just more of structuring design. And it doesn’t have to be “commercial” or work just like another, I just need something to get me going.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:36:24+00:00Added an answer on May 20, 2026 at 12:36 pm

    You could write a parser that looks for commands like

    /object_property value
    /object_method arg1 arg2
    

    A dictionary, like you suggested, could map those strings to properties and functions. The creation of the dictionary could be done dynamically using reflection by looping through eligible objects, taking their public methods and accessors, and generating a string for them.

    Then the dictionary could be mapped in a class for convenience and error checking.

    For the methods, the dictionary values could be delegates that take 0..n arguments, for the properties/fields, you will need to be able to some data binding between your actual fields and the dictionary value. UNLESS, your objects themselves refer to the dictionaries for their values, in which case the values only live in place.

    To do so, you could simply register your properties using reflection in the object constructor, then call the dictionary in your properties.

    [Flags]
    public enum CVarAccessibilities
    {
         Settable,
         Gettable
    }
    
    public class CVar<T>
    {
         public CVarAccessibilities Accessibility { get; set; }
         T val;
         public T Value { 
            get { return val; }
            set
            {
                 if (!Accessibility.HasFlag(CVarAccessibilities.Settable))
                      return; // just don't set it, maybe print some warning
                 val = value;
            }
         }
    }
    
    public static class CVarRegistry
    {
         static Dictionary<string, Object> CVars;
    
         static CVarRegistry { /* use reflections to initialize the dictionary */ }
    
         public static T GetValue<T>(Type owner, string paramName)
         {
              CVar cvar;
              if (!CVars.TryGetValue(owner.Name + "_" + paramName, out cvar)
                     throw new MyCustomException();
              return (T)cvar.Value;
         }
    
         public static void SetValue<T>(Type owner, string paramName, T value)
         {
              CVar cvar;
              if (!CVars.TryGetValue(owner.Name + "_" + paramName, out cvar)
                     throw new MyCustomException();
              cvar.Value = value;
         }
    }
    
    
    
    public class MyObject
    {
        public static int MyRegisteredValue
        {
            get { return Global.CVarRegistry.GetValue<int>(typeof(MyObject), "MyRegisteredValue");  }
            set { Global.CVarRegistry.SetValue(typeof(MyObject), "MyRegisteredValue"); }
        }
     }
    

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to update my SQL lite database with the native update-method of
I would like to get a sum from a column, with and without a
I would like to remove/delete a migration file. How would I go about doing
(please excuse that I didn't use aliases). I would like my query output to
There doesn't seem to be any tried and true set of best practices to
I know its probably possible, but is it practical and doable to try and
I'm trying to write test harness for part of my Android mapping application. I
I want to have generalised email templates. Currently I have multiple email templates with
I want the messagebox to only show if the number is equal to 0.
My question is about memory use and objects in actionscript 2. If I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.