<h2>Creating a configuration file with a single variable<aclass="headerlink" href="#creating-a-configuration-file-with-a-single-variable" title="Link to this heading">¶</a></h2>
<p>The entry point to the config module is the <aclass="reference internal" href="../modules/config.manager.html#config.manager.ConfigManager" title="config.manager.ConfigManager"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">config.manager.ConfigManager</span></code></a>
class. This class is effectively a representation of your configuration file
in Python. It allows you to perform a number of operations to your config
file. You can add console variables as well as commands to execute. The
<aclass="reference internal" href="../modules/config.manager.html#config.manager.ConfigManager" title="config.manager.ConfigManager"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">config.manager.ConfigManager</span></code></a> class will also place information about
each console variable in a comment block above the actual variable. Here is an
example script that creates a configuration file called <codeclass="docutils literal notranslate"><spanclass="pre">addon.cfg</span></code> in
<codeclass="docutils literal notranslate"><spanclass="pre">../cfg/source-python/</span></code>. This configuration file contains a single variable
called <codeclass="docutils literal notranslate"><spanclass="pre">addon_player_damage</span></code> which defaults to 64:</p>
<spanclass="s1">'How much damage to cause to each player.'</span><spanclass="p">,</span><spanclass="n">ConVarFlags</span><spanclass="o">.</span><spanclass="n">CHEAT</span>
<spanclass="p">)</span>
<spanclass="c1"># Write the configuration file out to the folder.</span>
<h2>Adding additional documentation to console variables<aclass="headerlink" href="#adding-additional-documentation-to-console-variables" title="Link to this heading">¶</a></h2>
<p>The config package allows you to write in additional information about a given
console variable. These appear as a header comment section above the variable.
The following example script adds a comment block above <codeclass="docutils literal notranslate"><spanclass="pre">addon_player_damage</span></code>
called <codeclass="docutils literal notranslate"><spanclass="pre">Description</span></code>:</p>
<spanclass="s1">'How much damage to cause to each player.'</span><spanclass="p">,</span><spanclass="n">ConVarFlags</span><spanclass="o">.</span><spanclass="n">CHEAT</span>
<spanclass="p">)</span>
<spanclass="c1"># I want to add some extra documentation for this variable.</span>
<spanclass="c1"># This creates a comment block called 'Description' right above</span>
// * Here is additional documentation on addon_player_damage.
// * Even more documentation.
// Default Value: 64
// How much damage to cause to each player.
addon_player_damage "64"
</pre></div>
</div>
<p>Couple of key takeaways from this example:</p>
<olclass="arabic simple">
<li><p>The <aclass="reference internal" href="../modules/config.manager.html#config.manager.ConfigManager.cvar" title="config.manager.ConfigManager.cvar"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">config.manager.ConfigManager.cvar()</span></code></a> and <aclass="reference internal" href="../modules/config.manager.html#config.manager.ConfigManager.command" title="config.manager.ConfigManager.command"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">config.manager.ConfigManager.command()</span></code></a> methods return objects which you can add string fields to. These fields get written as comment blocks above your console variable.</p></li>
<li><p>A server operator can change the default values in the configuration file. These changes will remain even if you call <aclass="reference internal" href="../modules/config.manager.html#config.manager.ConfigManager.write" title="config.manager.ConfigManager.write"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">config.manager.ConfigManager.write()</span></code></a>.</p></li>
</ol>
</section>
<sectionid="adding-sections">
<h2>Adding sections<aclass="headerlink" href="#adding-sections" title="Link to this heading">¶</a></h2>
<p>Adding sections to your configuration file is extremely simple. Just call the
<aclass="reference internal" href="../modules/config.manager.html#config.manager.ConfigManager.section" title="config.manager.ConfigManager.section"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">config.manager.ConfigManager.section()</span></code></a> method. You can also pass in a
character to use in order to create the section boundaries:</p>
<spanclass="s1">'How much damage to cause to each player.'</span><spanclass="p">,</span><spanclass="n">ConVarFlags</span><spanclass="o">.</span><spanclass="n">CHEAT</span>
<spanclass="p">)</span>
<spanclass="c1"># I want to add some extra documentation for this variable.</span>
<spanclass="c1"># This creates a comment block called 'Description' right above</span>
<spanclass="s1">'Model to set on the player.'</span><spanclass="p">,</span><spanclass="n">ConVarFlags</span><spanclass="o">.</span><spanclass="n">CHEAT</span>
<spanclass="p">)</span>
<spanclass="c1"># Write the configuration file out to the folder.</span>
<spanclass="c1"># Any values modified by the server administrator will</span>
<h2>Using context management<aclass="headerlink" href="#using-context-management" title="Link to this heading">¶</a></h2>
<p>All of the above examples show explicitly calling the <aclass="reference internal" href="../modules/config.manager.html#config.manager.ConfigManager.write" title="config.manager.ConfigManager.write"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">config.manager.ConfigManager.write()</span></code></a>
and <aclass="reference internal" href="../modules/config.manager.html#config.manager.ConfigManager.execute" title="config.manager.ConfigManager.execute"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">config.manager.ConfigManager.execute()</span></code></a> methods. You can also
automatically call these by using context management:</p>
<spanclass="s1">'How much damage to cause to each player.'</span><spanclass="p">,</span><spanclass="n">ConVarFlags</span><spanclass="o">.</span><spanclass="n">CHEAT</span>
<li><aclass="reference internal" href="#creating-a-configuration-file-with-a-single-variable">Creating a configuration file with a single variable</a></li>
<li><aclass="reference internal" href="#adding-additional-documentation-to-console-variables">Adding additional documentation to console variables</a></li>