This article's documentation is for anything that uses the Source engine. Click here for more information.

ConVar: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
(→‎Good Practices: fcvar_cheat doesn't always work; this is abused in portal speedruns for airboat%)
 
(47 intermediate revisions by 21 users not shown)
Line 1: Line 1:
[http://mepacon.com/data/larp/lart/sdvkcd.html lindsay lohan nip slip] [http://atlanticwindow.net/images/Doors/door/picture/hftbjk.html oma sex] [http://billdailey.net/maptest/images/jemnjp.html flava flav] [http://encksgunbarn.com/templates_c/tmp/joaemd.html kogal galleries] [http://robmorgan.net/images-lancaster/lan/tmp/preeme.html reagent grade water] [http://mepacon.com/data/larp/lart/uatesg.html red yeast rice] [http://mepacon.com/data/larp/lart/ijsomj.html lingerie pic satin] [http://quakermaid.com/upload/tmp/fmpuka.html lesbian slave] [http://amfm2go.com/images/Image/img/exwgsd.html small business finance] [http://playstation3facts.com/datas/img/icon/acqsvw.html strange pussy] [http://gethairless.com/media/mp3/melodiy/wwgxia.html preteen girls in thongs] [http://trickropingbylassue.com/media/video/gpg/wsgqlq.html dildo in pussy] [http://encksgunbarn.com/templates_c/tmp/pxaxgl.html promotional mugs] [http://waterbedheaven.com/images/premier/cache/tmp/ewfbqf.html teeny thong] [http://metalsculptures.com/images/img/tmp/kxdbqi.html alcohol treatment programs] [http://executiveautogallery.com/data/cars/small/kemjed.html constantinople] [http://abceastpa.org/myuploads/File/tmp/lxkuwc.html agenda for children new orleans] [http://harmonysandgravel.com/pre-art/art/cache/knajbi.html state of connecticut] [http://secondstreetspeed.com/faq/faq/img/qutuud.html hooked on a feeling] [http://drjekyllrocks.com/photogallery/photo/1/unwuhe.html tony little] [http://secondstreetspeed.com/faq/faq/img/pcibio.html driveway alarms] [http://playstation3facts.com/datas/img/icon/iulthw.html baby bibs] [http://gethairless.com/media/mp3/melodiy/hlfhoq.html child rape] [http://encksgunbarn.com/templates_c/tmp/wtnmxb.html teenager] [http://secondstreetspeed.com/faq/faq/img/qquinq.html banana tree] [http://abceastpa.org/myuploads/File/tmp/bmwihn.html business notes] [http://executiveautogallery.com/data/cars/small/rocwgt.html gay foot fetish] [http://amfm2go.com/images/Image/img/cfjxra.html jen] [http://drjekyllrocks.com/photogallery/photo/1/thtrrd.html jennysbookmarks] [http://www.globaltable.com/imageuploads/small/nsqdwp.html toon pussy] [http://secondstreetspeed.com/faq/faq/img/cutxbm.html pute] [http://stargalaxypub.com/images/pics/img/btpnnq.html carwash] [http://amfm2go.com/images/Image/img/hhclvr.html sea lice] [http://harmonysandgravel.com/pre-art/art/cache/okwgls.html certified financial manager] [http://drjekyllrocks.com/photogallery/photo/1/wmwrmr.html house of representatives] [http://secondstreetspeed.com/faq/faq/img/vmvlnl.html xl] [http://secondstreetspeed.com/faq/faq/img/bgwfiv.html cnc programming software] [http://wcmfl.org/Forms/doc/docs/itlhdb.html delphi forums] [http://berksaidsnetwork.org/photogallery/photo00001379/photo/wwdicl.html mini bike parts] [http://playstation3facts.com/datas/img/icon/bsphts.html adidas logo] [http://playstation3facts.com/datas/img/icon/stejsh.html msi] [http://atlanticwindow.net/images/Doors/door/picture/mdiabr.html susan hutchison] [http://u4it.com/images/videos/mpg/seoomh.html camping supplies] [http://encksgunbarn.com/templates_c/tmp/uocehw.html the importance of critical thinking for fresh graduates] [http://mepacon.com/data/larp/lart/emduas.html boobage] [http://encksgunbarn.com/templates_c/tmp/cgfbkj.html bumper sticker] [http://playstation3facts.com/datas/img/icon/qrrqnq.html valley stream station] [http://encksgunbarn.com/templates_c/tmp/xqhohj.html above ground pool liner] [http://waterbedheaven.com/images/premier/cache/tmp/rojoph.html letter personal sample thank] [http://quakermaid.com/upload/tmp/kmlklq.html breast sucking] [http://berksaidsnetwork.org/photogallery/photo00001379/photo/kiqpjf.html tv listings] [http://secondstreetspeed.com/faq/faq/img/heikgv.html land claims commission] [http://robmorgan.net/images-lancaster/lan/tmp/lhgpaw.html hot asians] [http://www.globaltable.com/imageuploads/small/ucclts.html secretary porn] [http://billdailey.net/maptest/images/ixnmcn.html medical equipment supplier] [http://executiveautogallery.com/data/cars/small/xwtdca.html gothic babes] [http://mepacon.com/data/larp/lart/uaptha.html sweet young pussy] [http://gethairless.com/media/mp3/melodiy/hxllpn.html spherion] [http://secondstreetspeed.com/faq/faq/img/jmdblt.html sister act 2] [http://harmonysandgravel.com/pre-art/art/cache/mqtant.html lot more to me] [http://drjekyllrocks.com/photogallery/photo/1/fllbtw.html ralph stanley] [http://u4it.com/images/videos/mpg/cghljk.html kermit weeks] [http://stargalaxypub.com/images/pics/img/rrhmji.html pictures of a phoenix bird] [http://atlanticwindow.net/images/Doors/door/picture/wfqjdl.html seach engines] [http://atlanticwindow.net/images/Doors/door/picture/gppkpe.html pda review] [http://trickropingbylassue.com/media/video/gpg/mmnapk.html zebra information for children] [http://secondstreetspeed.com/faq/faq/img/nuftec.html mature tales] [http://www.globaltable.com/imageuploads/small/qclpix.html stand by me lyric and music] [http://peterlenkefi.com/photos/albums/userpics/1001/jekaxl.html wedgy] [http://wcmfl.org/Forms/doc/docs/vnlare.html malegalaxy] [http://trickropingbylassue.com/media/video/gpg/arvtrw.html sun sentinel] [http://amfm2go.com/images/Image/img/kstcnp.html chinese medicine cancer chemotherapy detox] [http://peterlenkefi.com/photos/albums/userpics/1001/prixwm.html hair growth] [http://waterbedheaven.com/images/premier/cache/tmp/butcab.html ajax] [http://secondstreetspeed.com/faq/faq/img/nwepaw.html feminine little boys] [http://playstation3facts.com/datas/img/icon/bikwnn.html ebony slut galleries] [http://nkibuilders.com/jpg/icons/1/ctwvtj.html edward scissorhands] [http://consumerfireproducts.com/ccount/cache/fquqgr.html paris hilton cum] [http://executiveautogallery.com/data/cars/small/xosvgg.html t shirt men] [http://mepacon.com/data/larp/lart/vftwsc.html brianabanks] [http://executiveautogallery.com/data/cars/small/mpehhe.html gay celebrities] [http://u4it.com/images/videos/mpg/xpxivf.html nichole richie nude] [http://www.globaltable.com/imageuploads/small/rdkpae.html lit my own worst enemy] [http://metalsculptures.com/images/img/tmp/ojscuu.html jennifer korbin] [http://berksaidsnetwork.org/photogallery/photo00001379/photo/rksxdf.html new york state theater at lincoln center] [http://executiveautogallery.com/data/cars/small/xmjrps.html short skirt galleries] [http://mepacon.com/data/larp/lart/fxhotu.html cum clips] [http://secondstreetspeed.com/faq/faq/img/sikuvw.html anal virgin pain] [http://abceastpa.org/myuploads/File/tmp/lsgspc.html hoobastank mp3] [http://gethairless.com/media/mp3/melodiy/cuqluk.html what is a rss feed] [http://encksgunbarn.com/templates_c/tmp/cxoaex.html ww1 women at war] [http://wcmfl.org/Forms/doc/docs/weejfk.html military shadow boxes] [http://www.globaltable.com/imageuploads/small/igdgmp.html weight gain] [http://drjekyllrocks.com/photogallery/photo/1/kvpuij.html ottawa map] [http://amfm2go.com/images/Image/img/lgnsgp.html silk screen] [http://guthsville.com/Download/Bullseye/tmp/1/rqgckb.html bond girls nude] [http://drjekyllrocks.com/photogallery/photo/1/glprko.html hot dog cart advice] [http://atlanticwindow.net/images/Doors/door/picture/kpfxfs.html home design software] [http://drjekyllrocks.com/photogallery/photo/1/wxcurb.html dunlop tires] [http://amfm2go.com/images/Image/img/bjjian.html championship ring]
{{LanguageBar}}
For a description, see [[Developer_Console#Commands_and_Variables|Commands and Variables]].
{{src topicon}}
 
{{stub}}
 
'''ConVar''' is the C++ class used to create a [[console variable]] (frequently shortened to "cvar"), which is used in the [[Developer Console]].
 
Documentation on specific console variables can be found at [[:Category:Console variables]].
For creating a new Console Variable see this. [[Developer_Console_Control#Using_the_ConVar_class|Developer Console Control]]


Documentation on specific console variables can be found at [[:Category:Console Variables]].
<!-- only info on console variables _in general_ should be on this page -->
<!-- only info on console variables _in general_ should be on this page -->
==Good Practices==
 
Commands that are wish to be saved should be marked with flag [[FCVAR_ARCHIVE]]. Any cheat ConVar defined should not be archived.
ConVar uses the constructor shown below:
[[Category:Glossary]]
 
{{code|highlight=cpp|ConVar( const char *pName, const char *pDefaultValue, int flags, const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax );}}
 
The default value given as the second argument of the ConVar constructor is '''not''' the value set. To set a value, use:
 
{{code|highlight=cpp|pName->SetValue([value])}};
 
== Good Practices ==
* Variables that you wish to be saved should be marked with flag [[FCVAR_ARCHIVE]]. These will be saved with the user bindings in <code>config.cfg</code>. Any cheat cvar should not be archived.
 
* After whatever flags you may want to add (or 0 if you don't want any), you can set a help string. This will display when someone enters in the ConVar without any value or if they enter an invalid value. You can use {{code|\n}} to make a new line and use spaces after that to indent lines. Make your help-strings as rich and detailed as you want!
 
* Use the flag [[FCVAR_CHEAT]] to signify a ConVar that can only be used when sv_cheats is turned on.
:{{bug|Some games will ignore this flag in singleplayer.}}
* Use the flag [[FCVAR_REPLICATED]] to signify a server variable which is then ''replicated'' onto clients. For example, round timers or game rules should have this flag.
 
* For multiplayer games, use [[FCVAR_NOTIFY]] to send a message in chat whenever this variable is changed. Use this for ConVars that change game mechanics.
 
For more tips using ConVar flags, see [[Developer Console Control#The FCVAR flags|this page]].
 
== Examples ==
The code below will define a cvar named <code>cl_test</code>:
 
{{code|highlight=cpp|ConVar cl_test("cl_test", 0, 0, "Example ConVar");}}
 
Whats happening here is first, we are declaring the variable to be a <code>ConVar</code>, then we are setting the name of the cvar that would be used in games console,
and after that, we set the default value, then flags, and finally, the help text for the console.
 
We can use use these cvars to initialize other variables, like if you wanted to create a integer named test you could do as so
 
{{code|highlight=cpp|int test {{=}} cl_test.GetInt();}}
 
You could also have it be a float, and call <code>GetFloat()</code>
 
Finally, don't forget to include <code>convar.h</code> in your file
 
== See also ==
[[Developer Console Control]]
[[Category:Classes]]

Latest revision as of 16:22, 4 June 2025

English (en)Español (es)Русский (ru)Translate (Translate)

Stub

This article or section is a stub. You can help by expanding it.

ConVar is the C++ class used to create a console variable (frequently shortened to "cvar"), which is used in the Developer Console.

Documentation on specific console variables can be found at Category:Console variables. For creating a new Console Variable see this. Developer Console Control


ConVar uses the constructor shown below:

ConVar( const char *pName, const char *pDefaultValue, int flags, const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax );

The default value given as the second argument of the ConVar constructor is not the value set. To set a value, use:

pName->SetValue([value]);

Good Practices

  • Variables that you wish to be saved should be marked with flag FCVAR_ARCHIVE. These will be saved with the user bindings in config.cfg. Any cheat cvar should not be archived.
  • After whatever flags you may want to add (or 0 if you don't want any), you can set a help string. This will display when someone enters in the ConVar without any value or if they enter an invalid value. You can use \n to make a new line and use spaces after that to indent lines. Make your help-strings as rich and detailed as you want!
  • Use the flag FCVAR_CHEAT to signify a ConVar that can only be used when sv_cheats is turned on.
Icon-Bug.pngBug:Some games will ignore this flag in singleplayer.  [todo tested in ?]
  • Use the flag FCVAR_REPLICATED to signify a server variable which is then replicated onto clients. For example, round timers or game rules should have this flag.
  • For multiplayer games, use FCVAR_NOTIFY to send a message in chat whenever this variable is changed. Use this for ConVars that change game mechanics.

For more tips using ConVar flags, see this page.

Examples

The code below will define a cvar named cl_test:

ConVar cl_test("cl_test", 0, 0, "Example ConVar");

Whats happening here is first, we are declaring the variable to be a ConVar, then we are setting the name of the cvar that would be used in games console, and after that, we set the default value, then flags, and finally, the help text for the console.

We can use use these cvars to initialize other variables, like if you wanted to create a integer named test you could do as so

int test = cl_test.GetInt();

You could also have it be a float, and call GetFloat()

Finally, don't forget to include convar.h in your file

See also

Developer Console Control