Developer console: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (please comment on the article using the discussion page, not the article itself)
No edit summary
Line 1: Line 1:
== Overview ==
[[Image:Console.gif|right|Console output for Episode Two]]
[[Image:Developer-console.jpg|right]]
The developer console allows you to enter commands to the Source engine while testing a map or mod.


Typing <code>[[help]]</code> will provide some instructions.
The '''console''' provides a [[Wikipedia:Command-line interface|command-line interface]] for the advanced configuration of Source games. Just about any configuration task can be completed from the console, and indeed they often have to be.
 
Type <code>[[find]] <substring></code> to look for [[ConCommand|console command]]s or [[ConVar|console variables]] related to a specific topic (i.e. typing <code>find npc</code> would show a listing of [[NPC Debugging Command]]s such as [[npc_go]] and [[npc_create]].
 
== Introduction ==
The developer console is an essential tool for game developers for debugging their code and also for players to customize their settings. The console is a text-based input/output interface to execute commands or change global settings during runtime.  


== Enabling the console ==
== Enabling the console ==
To enable the console for use:


# Run the game/mod.
The console starts disabled. To enable it, load the game and visit ''Options > Keyboard > Advanced''. Once enabled, it can be opened and closed by pressing the button above {{key|Tab}}.
# In the main menu click on ''Options''.
# Click the ''Keyboard'' tab.
# Click the ''Advanced...'' button.
# Check the box next to ''Enable developer console (~)''.
# Click ''Apply''.


Henceforth, the console can be opened or closed with the key located top left below <Escape>, typically labeled '''~''' ("tilde") on a US keyboard.
(This should work regardless of your keyboard layout. If it doesn't, add <code>-console</code> to the game's launch options and type <code>bind your_key toggleconsole</code>.)


{{note|The '''~''' key may not work on some keyboards, in which case you should right click on the game, and add <code>-console</code> in launch options. When the game has launched, the console should be open, enter <code>bind <key-you-want-to-use> toggleconsole</code>
== Submitting ==
Replace <key-you-want-to-use> with the key you want to use. Eg:
<code>bind t toggleconsole</code>


You can also manually set another key by opening the ''cfg/config.cfg'' file of the game/mod and changing this line:
The grey box across the bottom of the console window is where commands are entered. They come in two forms: commands and variables. Commands are simply keywords, but variables ("cvars") require a value of some sort before they are accepted. When setting a cvar you might type something like this :
<code>bind "<key-you-want-to-use>" "toggleconsole"</code>
German keyboard layout: To use the key left to '''1''' which reads '''^''', do <code>bind "\" "toggleconsole"</code>}}


The console is also enabled when the game executable is started with the <code>-dev</code> or <code>-console</code> parameters. (Developers should always start the game with <code>-dev</code>.)
find_ent [[point_viewcontrol]]


If the Source Engine is started with an attached debugger, the console output is shown in your debug output window.
When you've finished typing, hit {{key|Return}} or {{key|Enter}} to submit. You'll see everything you type 'echoed' to the console with a preceding <code>]</code>.


Starting HL with <code>-condebug</code> will also log all console output in the text file <code>console.log</code> located in your game directory.
A few notes:


== Entering commands ==
* Multiple values are separated with spaces. If a value contains a space, surround it with quote marks. (e.g. <code>say "Hello everyone on the server"</code>.)
Commands are entered into the console by typing them in at the box at the bottom. After entering a new command, it is executed by hitting the <Return> key or pressing the ''Submit'' button.
* The console will suggest commands and sometimes values in a pop-out box beneath the input field. Press {{key|Up}}/{{key|Down}} to navigate the list and {{key|Tab}} to accept the highlighted suggestion.
* Only "archived" cvars are stored after the game closes. Use [[autoexec]] if you want to set any others when a game loads.
* Some commands are serverside, others clientside. In multiplayer you can only set clientside ones.
* There are many command prefixes. The most common are <code>cl</code> ("clientside") and <code>sv</code> ("serverside").


A command has a unique name and an optional list of parameters where each parameter is separated by a <Space> character.
== Useful commands ==


{{note|The <code>]</code> is a prompt, and is not typed.}}
; <code>find <term></code>
: The ever-useful <code>find</code> command searches console command names and descriptions for the term your provide.
; <code>help <command name></code>
: Displays any help text for a command, without affecting its value.
;<code>sv_cheats <[[bool]]></code>
: Most cvars that affect gameplay, especially in multiplayer games, are flagged as "cheats". Submit <code>sv_cheats 1</code> to unlock them. {{note|You will never be [[Valve Anti-Cheat|VAC]] banned for using built-in cheat commands.}}
;<code>developer <0-2></code>
:Developer mode enables more verbose console output, enables cheats and the console automatically, and makes various other useful changes. If set to <code>2</code>, the last few lines of console output will be printed at the top of the screen as well.
;<code>con_log <file></code>
;<code>condump</code>
: Use one of these commands if you want to record what goes on in the console for later use. <code>con_log</code> writes output constantly, while <code>condump</code> records only when invoked. {{tip|The console only displays 241 lines at a time. Use <code>con_log</code> if you run up against this.}}  


The syntax is: <code>command <parameter1> [<parameter2>]</code>. For example:
<!-- not convinced that this is useful == Command prefixes ==


<pre>
Commands traditionally come with prefixes that go some way to categorising them. Common ones include:
]bind mouse1 +attack
]map dm_lockdown
</pre>


If a command parameter contains <Space> characters, it must be encapsulated in quotes:
=== Clientside ===


<pre>
;<code>cl_</code>
]bind h "say hello world"
:Generic clientside
]name "Gordon Freeman"
;<code>demo_</code>
</pre>
:[[Demo]] recording and playback
;<code>r_</code>
:Generic rendering configuration
;<code>mat_</code>
:[[Material]] configuration
;<code>hud_</code>
:In-game user interface
;<code>net_</code>
:[[:Category:Networking|Networking]] configuration (a few are serverside)


The console stores the last executed commands in a command history that is accessible with <UpArrow> (goes to the command you just/last entered) and <DownArrow> (goes to the very first command that you entered into the console) keys. You can auto complete a command by pressing <Tab> and choose from a list of available commands if the console found multiple matches. Some commands (e.g. <code>map</code>, <code>load</code> etc) support auto completion for the first parameter too.
=== Serverside ===


== Commands and variables ==
;sv_
The console differs between console commands and console variables.
:Generic serverside
;g_
:Generic singleplayer configuration
;mp_
:Generic multiplayer configuration
;ent_
:Direct entity control
;npc_
:Direct NPC control
;phys_
:Physics adjustments
;sk_
:Difficulty ("skill")
-->
== Setting cvars with C++ ==


''Console commands'' usually pass the parameters to some code function and execute it, but they don't remember these parameters.
Simply:


''Console variables'' store the last parameters like a global setting. Console variables can only have one parameter, which can be a number or string; it depends on the game code how these values are interpreted. A lot of console variables act like triggers, 0 usually means off and 1 means on (e.g. <code>cl_showfps</code>). To see the current value of a console variable just type the name without any parameters.
[the_cvar]->SetValue( [value] );


Most console commands and variables have prefixes in their name to show the subsystem they belong to, but this isn't always the case, especially for commands coming from Half-Life 1, where the old name was kept unchanged.
If you do not have access to a cvar, do this first:


Commonly used console command prefixes are:
ConVar *[the_cvar] = cvar->FindVar( "[the_cvar]" );
{|
| <code>ai_</code> || single player AI
|-
| <code>bot_</code> || bot system
|-
| <code>cc_</code> || close caption system
|-
| <code>cl_</code> || multiplayer client
|-
| <code>demo_</code> || demo playback
|-
| <code>disp_</code> || terrain displacement maps
|-
| <code>dsp_</code> || audio DSP settings
|-
| <code>ent_</code> || entity control/debug
|-
| <code>fire_</code> || firing entity events
|-
| <code>fog_</code> || fog renderer
|-
| <code>g_</code> || single player game
|-
| <code>hltv_</code> || Half-Life TV
|-
| <code>host_</code> || host system
|-
| <code>hud_</code> || client HUD
|-
| <code>joy_</code> || joystick input
|-
| <code>log_</code> || logging system
|-
| <code>m_</code> || mouse input
|-
| <code>mat_</code> || material system
|-
| <code>mp_</code> || multiplayer game (server)
|-
| <code>nav_</code> || navigation graphs
|-
| <code>net_</code> || engine networking
|-
| <code>npc_</code> || single player game NPCs
|-
| <code>phys_</code> || physics system
|-
| <code>r_</code> || video renderer
|-
| <code>rcon_</code> || remote control access
|-
| <code>sk_</code> || player skill / difficulty
|-
| <code>snd_</code> || sound system
|-
| <code>sv_</code> || server settings (engine)
|-
| <code>v_</code> || client view
|-
| <code>vgui_</code> || VGUI
|-
| <code>voice_</code> || ingame player voice
|-
| <code>vprof_</code> || code profiler
|-
| <code>wc_</code> || WorldCraft/Hammer helpers
|}


If you forgot the exact name of a command or variable, <code>find <substring></code> shows all commands containing a given substring.
{{tip|This code works even for closed-source cvars.}}


The command <code>help <command></code> shows help text for a given command (if available).
{{todo|How to directly execute concommands?}}


== Entering cheats into the console==
== See also ==
If you wish to enter a cheat such as [[impulse| impulse 101]] then you would need to have already typed in [[sv_cheats| sv_cheats 1]]. This enables the cheats to be typed in. To turn cheats off simply type in [[sv_cheats| sv_cheats 0]].


== See also ==
* [[Console Command List]] - partial list of console commands and variables
* [[Console Command List]] - A complete list of console commands and variables.
* [[:Category:Console Commands]] - list of written articles for console commands
* [[:Category:Console Commands]] - A list of articles on console commands.
* [[:Category:Console Variables]] - list of written articles for console variables
* [[:Category:Console Variables]] - A list of articles on console variables.


{{otherlang:en}}
{{otherlang:en}}
Line 156: Line 102:
{{otherlang:en:zh-tw|Developer Console:zh-tw}}
{{otherlang:en:zh-tw|Developer Console:zh-tw}}


[[Category:Level Design]]
[[Category:Modding]]
[[Category:Programming]]
[[Category:Programming]]

Revision as of 13:41, 15 January 2009

Console output for Episode Two

The console provides a command-line interface for the advanced configuration of Source games. Just about any configuration task can be completed from the console, and indeed they often have to be.

Enabling the console

The console starts disabled. To enable it, load the game and visit Options > Keyboard > Advanced. Once enabled, it can be opened and closed by pressing the button above Tab .

(This should work regardless of your keyboard layout. If it doesn't, add -console to the game's launch options and type bind your_key toggleconsole.)

Submitting

The grey box across the bottom of the console window is where commands are entered. They come in two forms: commands and variables. Commands are simply keywords, but variables ("cvars") require a value of some sort before they are accepted. When setting a cvar you might type something like this :

find_ent point_viewcontrol

When you've finished typing, hit Return or Enter to submit. You'll see everything you type 'echoed' to the console with a preceding ].

A few notes:

  • Multiple values are separated with spaces. If a value contains a space, surround it with quote marks. (e.g. say "Hello everyone on the server".)
  • The console will suggest commands and sometimes values in a pop-out box beneath the input field. Press / to navigate the list and Tab to accept the highlighted suggestion.
  • Only "archived" cvars are stored after the game closes. Use autoexec if you want to set any others when a game loads.
  • Some commands are serverside, others clientside. In multiplayer you can only set clientside ones.
  • There are many command prefixes. The most common are cl ("clientside") and sv ("serverside").

Useful commands

find <term>
The ever-useful find command searches console command names and descriptions for the term your provide.
help <command name>
Displays any help text for a command, without affecting its value.
sv_cheats <bool>
Most cvars that affect gameplay, especially in multiplayer games, are flagged as "cheats". Submit sv_cheats 1 to unlock them.
Note.pngNote:You will never be VAC banned for using built-in cheat commands.
developer <0-2>
Developer mode enables more verbose console output, enables cheats and the console automatically, and makes various other useful changes. If set to 2, the last few lines of console output will be printed at the top of the screen as well.
con_log <file>
condump
Use one of these commands if you want to record what goes on in the console for later use. con_log writes output constantly, while condump records only when invoked.
Tip.pngTip:The console only displays 241 lines at a time. Use con_log if you run up against this.

Setting cvars with C++

Simply:

[the_cvar]->SetValue( [value] );

If you do not have access to a cvar, do this first:

ConVar *[the_cvar] = cvar->FindVar( "[the_cvar]" );
Tip.pngTip:This code works even for closed-source cvars.
Todo: How to directly execute concommands?

See also

Template:Otherlang:en Template:Otherlang:en:es, Template:Otherlang:en:jp, Template:Otherlang:en:pl, Template:Otherlang:en:ru, Template:Otherlang:en:zh-tw