How The Console Works
SoulSkorpion
Join Date: 2002-04-12 Member: 423Members
<div class="IPBDescription">if you're confused by scripts</div> Ok, boys and girls. Some of you seem very confused by how scripts work, what you can do with scripts, and what the heck a .cfg file actually is. Hopefully, this should clear it up for you <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile.gif' border='0' style='vertical-align:middle' alt='smile.gif'><!--endemo-->
<b><span style='font-size:13pt;line-height:100%'>The Console</span></b>
Scripting, aliases, binds, .cfgs, all that sort of stuff are all based on the console. That's the thing that drops down when you press the ~ key. You can use the console to enter commands, kinda like DOS (er... that's probably a bad example.) Anyways, your keyboard configuration is actually set by a series of console commands.
"What? I've never touched the console! How can my config be set up by console commands?" I hear you cry. I'll get to that in a sec <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile.gif' border='0' style='vertical-align:middle' alt='smile.gif'><!--endemo-->
<b><span style='font-size:13pt;line-height:100%'>Binds</span></b>
You can use the console to "bind" a command to a key. For example, the console command <span style='font-family:Courier'>bind UPARROW +forward</span> will make you move forward when you press the up arrow. <span style='font-family:Courier'>bind x say Hello world! </span> will make you say "Hello world!" over global chat when you press x.
"But you said all my controls are handled by the console! When are you going to tell me about that?!"
Ok, ok, I'm getting there...
<b><span style='font-size:13pt;line-height:100%'>Config files</span></b>
A config file is a text file full of console commands, with a <span style='font-family:Courier'>.cfg</span> extention instead of <span style='font-family:Courier'>.txt</span>. You might have noticed a config file called <span style='font-family:Courier'>config.cfg</span> in your NS folder. Every HL mod (including HL itself) has a config.cfg file. You know when you set up your keyboard configuration through the options menu? The config.cfg is where that information gets stored. Every time you fire up NS and join a game, the config.cfg runs. That means it goes through the file line by line, and runs each line in the console.
So in other words, your config.cfg will have a whole bunch of lines like this:
<span style='font-family:Courier'>bind UPARROW +forward
bind LEFTARROW +moveleft
bind RIGHTARROW +moveright
bind DOWNARROW +back</span>
It will also have a whole bunch of settings for your volume, net settings, hud_fastswitch etc. These settings are called <b>cvars</b>, or <b>client variables</b>. Don't worry about them too much.
To sumarise config files:
The config.cfg file stores settings set by the options menu, as well as any changes you make using the console.
The autoexec.cfg file (which I don't think exists by default) is also run automatically, after the config.cfg.
The command <span style='font-family:Courier'>exec <i>filename</i>.cfg</span> can be used to run a config file. You can also stick this command IN a config file. So you could have a special script in a file called <span style='font-family:Courier'>myscript.cfg</span> and then have the line <span style='font-family:Courier'>exec myscript.cfg</span> in your autoexec.cfg.
<b><span style='font-size:13pt;line-height:100%'>Scripts and Aliases</span></b>
The way really ub3r-l337 scripts work (well, the way ANY decent script works) is something called an alias. An alias is kinda a made-up command, which can contain a whole bunch of real commands. Aliases are used if you want to have more than one command executed by a single button press.
Here's a ridiculous example:
<span style='font-family:Courier'>alias saytwothings "say Hello!; say I like Pie!"
bind x saytwothings</span>
When you press the x key, you will say "Hello!" and then "I like Pie!" over global chat.
What this does is makes up a command called "saytwothings". Once that command has been made up, you can treat it just like a built-in command. That means you can bind keys to it. Notice that you use semicolons to seperate commands in an alias (no, you don't need a semi after the last one, C++ people <!--emo&;)--><img src='http://www.unknownworlds.com/forums/html/emoticons/wink.gif' border='0' style='vertical-align:middle' alt='wink.gif'><!--endemo-->).
<b><span style='font-size:13pt;line-height:100%'>+commands</span></b>
You might notice that some commands are +something and some are not. For example, the command to switch to weapon 1 is <span style='font-family:Courier'>slot1</span> but the command to start firing is <span style='font-family:Courier'>+attack</span>. "Huh? What's going on here?"
These are special commands, which we'll call +commands (for lack of a better term). +commands always have a corresponding -command (well, most of the time. Er... just trust me on this one <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile.gif' border='0' style='vertical-align:middle' alt='smile.gif'><!--endemo-->). So the <span style='font-family:Courier'>+attack</span> command also has a <span style='font-family:Courier'>-attack</span> command. <span style='font-family:Courier'>+attack</span> makes you start attacking, and <span style='font-family:Courier'>-attack</span> makes you stop.
"So why do I need to know that?"
Well, it's possible to create your own +commands. For example, you could have a script which pulls out your knife and starts swinging, and switches to your primary weapon when you let go:
<span style='font-family:Courier'>alias +knife "slot3; +attack"
alias -knife "-attack; slot1"
bind x +knife
</span>
Notice that the <span style='font-family:Courier'>+knife</span> command starts you attacking, but doesn't stop. The matching <span style='font-family:Courier'>-attack</span> command is in the <span style='font-family:Courier'>-knife</span> alias.
[edit]Sorry. I didn't make one important thing clear. When you create your own +command and a corresponding -command and bind it to a key, the +command is run when you press the key and the -command is run when you release the key.[/edit]
"But then how come <span style='font-family:Courier'>bind mouse1 +attack</span> doesn't make me keep firing for ever and ever when I click?"
Ah. That's because the console is nice to you. If you use the <span style='font-family:Courier'>bind</span> command with a single +command the console will clean up all the mess for you.
On the other hand, if you use an alias....
<span style='font-family:Courier'>alias startattacking "+attack"
bind mouse1 startattacking</span>
This one will keep firing forever.
By the way, if you intend to muck around with scripting you will inevitably create a few scripts like the above which keep doing a +command for ever and ever. This is a bit of a problem - if you want to see what happens, pull down the console and enter in <span style='font-family:Courier'>+attack</span>. You will NOT be able to stop attacking, even by pressing (or clicking) your normal attack button.
So how can you clean up this sort of thing? Easy. Create a file called <span style='font-family:Courier'>stop.cfg</span> in your NS directory, and in it put something to the effect of this:
<span style='font-family:Courier'>-attack
-duck
-run
-jump
-forward
-back</span>
...etc. And then if you ever get stuck in a +command and you aren't sure which, just bring down the console and enter in <span style='font-family:Courier'>exec stop.cfg</span>
<b><span style='font-size:13pt;line-height:100%'>Conclusion</span></b>
Okay. That's the basics (actually, a little bit more than the basics) of how the console works. If you want a detailed list of console commands, as well as excellent console\scripting tutorials, head to <a href='http://half-life.gamehelp.com/console/index.html' target='_blank'>I.Am/Half-Life</a>. It's a very old site, but the console information is still current, and it's still an excellent reference. It's where I learned console scripting, all those years ago <!--emo&;)--><img src='http://www.unknownworlds.com/forums/html/emoticons/wink.gif' border='0' style='vertical-align:middle' alt='wink.gif'><!--endemo-->.
Anyways, I hope that enlightens some people about what people mean when they talk about config.cfg, and about what the console actually does. Have a play around with it, and don't be scared of it - you can't break anything. You can't screw up your Half-Life through the console. At worst, you'll have to reset your computer and re-do your keyboard config through the options menu. You can't erase HL, make your computer explode, or infect your computer with a mysterious virus through the console, so don't panic and HAVE FUN!
<b><span style='font-size:13pt;line-height:100%'>The Console</span></b>
Scripting, aliases, binds, .cfgs, all that sort of stuff are all based on the console. That's the thing that drops down when you press the ~ key. You can use the console to enter commands, kinda like DOS (er... that's probably a bad example.) Anyways, your keyboard configuration is actually set by a series of console commands.
"What? I've never touched the console! How can my config be set up by console commands?" I hear you cry. I'll get to that in a sec <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile.gif' border='0' style='vertical-align:middle' alt='smile.gif'><!--endemo-->
<b><span style='font-size:13pt;line-height:100%'>Binds</span></b>
You can use the console to "bind" a command to a key. For example, the console command <span style='font-family:Courier'>bind UPARROW +forward</span> will make you move forward when you press the up arrow. <span style='font-family:Courier'>bind x say Hello world! </span> will make you say "Hello world!" over global chat when you press x.
"But you said all my controls are handled by the console! When are you going to tell me about that?!"
Ok, ok, I'm getting there...
<b><span style='font-size:13pt;line-height:100%'>Config files</span></b>
A config file is a text file full of console commands, with a <span style='font-family:Courier'>.cfg</span> extention instead of <span style='font-family:Courier'>.txt</span>. You might have noticed a config file called <span style='font-family:Courier'>config.cfg</span> in your NS folder. Every HL mod (including HL itself) has a config.cfg file. You know when you set up your keyboard configuration through the options menu? The config.cfg is where that information gets stored. Every time you fire up NS and join a game, the config.cfg runs. That means it goes through the file line by line, and runs each line in the console.
So in other words, your config.cfg will have a whole bunch of lines like this:
<span style='font-family:Courier'>bind UPARROW +forward
bind LEFTARROW +moveleft
bind RIGHTARROW +moveright
bind DOWNARROW +back</span>
It will also have a whole bunch of settings for your volume, net settings, hud_fastswitch etc. These settings are called <b>cvars</b>, or <b>client variables</b>. Don't worry about them too much.
To sumarise config files:
The config.cfg file stores settings set by the options menu, as well as any changes you make using the console.
The autoexec.cfg file (which I don't think exists by default) is also run automatically, after the config.cfg.
The command <span style='font-family:Courier'>exec <i>filename</i>.cfg</span> can be used to run a config file. You can also stick this command IN a config file. So you could have a special script in a file called <span style='font-family:Courier'>myscript.cfg</span> and then have the line <span style='font-family:Courier'>exec myscript.cfg</span> in your autoexec.cfg.
<b><span style='font-size:13pt;line-height:100%'>Scripts and Aliases</span></b>
The way really ub3r-l337 scripts work (well, the way ANY decent script works) is something called an alias. An alias is kinda a made-up command, which can contain a whole bunch of real commands. Aliases are used if you want to have more than one command executed by a single button press.
Here's a ridiculous example:
<span style='font-family:Courier'>alias saytwothings "say Hello!; say I like Pie!"
bind x saytwothings</span>
When you press the x key, you will say "Hello!" and then "I like Pie!" over global chat.
What this does is makes up a command called "saytwothings". Once that command has been made up, you can treat it just like a built-in command. That means you can bind keys to it. Notice that you use semicolons to seperate commands in an alias (no, you don't need a semi after the last one, C++ people <!--emo&;)--><img src='http://www.unknownworlds.com/forums/html/emoticons/wink.gif' border='0' style='vertical-align:middle' alt='wink.gif'><!--endemo-->).
<b><span style='font-size:13pt;line-height:100%'>+commands</span></b>
You might notice that some commands are +something and some are not. For example, the command to switch to weapon 1 is <span style='font-family:Courier'>slot1</span> but the command to start firing is <span style='font-family:Courier'>+attack</span>. "Huh? What's going on here?"
These are special commands, which we'll call +commands (for lack of a better term). +commands always have a corresponding -command (well, most of the time. Er... just trust me on this one <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile.gif' border='0' style='vertical-align:middle' alt='smile.gif'><!--endemo-->). So the <span style='font-family:Courier'>+attack</span> command also has a <span style='font-family:Courier'>-attack</span> command. <span style='font-family:Courier'>+attack</span> makes you start attacking, and <span style='font-family:Courier'>-attack</span> makes you stop.
"So why do I need to know that?"
Well, it's possible to create your own +commands. For example, you could have a script which pulls out your knife and starts swinging, and switches to your primary weapon when you let go:
<span style='font-family:Courier'>alias +knife "slot3; +attack"
alias -knife "-attack; slot1"
bind x +knife
</span>
Notice that the <span style='font-family:Courier'>+knife</span> command starts you attacking, but doesn't stop. The matching <span style='font-family:Courier'>-attack</span> command is in the <span style='font-family:Courier'>-knife</span> alias.
[edit]Sorry. I didn't make one important thing clear. When you create your own +command and a corresponding -command and bind it to a key, the +command is run when you press the key and the -command is run when you release the key.[/edit]
"But then how come <span style='font-family:Courier'>bind mouse1 +attack</span> doesn't make me keep firing for ever and ever when I click?"
Ah. That's because the console is nice to you. If you use the <span style='font-family:Courier'>bind</span> command with a single +command the console will clean up all the mess for you.
On the other hand, if you use an alias....
<span style='font-family:Courier'>alias startattacking "+attack"
bind mouse1 startattacking</span>
This one will keep firing forever.
By the way, if you intend to muck around with scripting you will inevitably create a few scripts like the above which keep doing a +command for ever and ever. This is a bit of a problem - if you want to see what happens, pull down the console and enter in <span style='font-family:Courier'>+attack</span>. You will NOT be able to stop attacking, even by pressing (or clicking) your normal attack button.
So how can you clean up this sort of thing? Easy. Create a file called <span style='font-family:Courier'>stop.cfg</span> in your NS directory, and in it put something to the effect of this:
<span style='font-family:Courier'>-attack
-duck
-run
-jump
-forward
-back</span>
...etc. And then if you ever get stuck in a +command and you aren't sure which, just bring down the console and enter in <span style='font-family:Courier'>exec stop.cfg</span>
<b><span style='font-size:13pt;line-height:100%'>Conclusion</span></b>
Okay. That's the basics (actually, a little bit more than the basics) of how the console works. If you want a detailed list of console commands, as well as excellent console\scripting tutorials, head to <a href='http://half-life.gamehelp.com/console/index.html' target='_blank'>I.Am/Half-Life</a>. It's a very old site, but the console information is still current, and it's still an excellent reference. It's where I learned console scripting, all those years ago <!--emo&;)--><img src='http://www.unknownworlds.com/forums/html/emoticons/wink.gif' border='0' style='vertical-align:middle' alt='wink.gif'><!--endemo-->.
Anyways, I hope that enlightens some people about what people mean when they talk about config.cfg, and about what the console actually does. Have a play around with it, and don't be scared of it - you can't break anything. You can't screw up your Half-Life through the console. At worst, you'll have to reset your computer and re-do your keyboard config through the options menu. You can't erase HL, make your computer explode, or infect your computer with a mysterious virus through the console, so don't panic and HAVE FUN!
Comments
*sticky the thang
So the console doesn't work on your new shortcut huh? Its really quite simple to fix. First right click on the new shortcut. Out of the menu choose properties. Look for something called target. It should have text that you can edit to the right of it. At the end of this text, put a space, then type in -console. Double click on your shortcut to open up NS. See that button at the top called Console? Open it. Then type in bind "`" "toggleconsole" and press enter. There, you can now pull down your console with `.
This is to help ou people that have made a new shortcut and can't figure out how to get the console back.
Name "namehere"
Changes your name to "namehere". Handy for chaning it on the fly so you don't have to back out and enter setup, possibly messing up a custom spray.
Stopsound
Clears all the current sounds the HL engine is running. This causes things which are repeadly playing a sound to stop doing it. That annoying stuck lift or door repeadly playing that horrendous GARRAGRGARGARGAGRGARGARGAGRAGRGGARGRGRG noise will now be silenced, allowing you to play in peace.
Password "passwordhere"
Alone, it shows what you current have set for the password when connecting to the server. When followed by "passwordhere" allows you to change it. Significantly more usful if you are using ASE, which only asks for the password directly the first time you connect to a server... then uses that password until you change it.
Retry
Allows you to retry your connection to the server. This takes you back to the inital point where you tried to connect to the server with the exact same IP. Very handy if you've lagged out and you need to reconnect, or the server has crashed and you need to reconnect.
net_graph "0-3"
Shows a net_graph, which depicts your crrent ping, FPS, data transfer, packetloss, and a chart that displays all this visually. However, it's worth noting that all the net_graphs cause some drop in FPS and eat memory. "0" deactivates. "1,2,3" are differing netgraphs with information displayed in diffrent ways... "3" removes the FPS-hogging chart completly and is probally the most desierable if you want to have it up while playing.
showfps
Shows a FPS counter without having to look at that clunky net_graph.
Allows you to switch weapons/attack with 1 keypress instead of a keypress + click.
<b>
bind pgup "+use ; +use"
bind pgdn "-use"
</b>
Push "Page Up" and you start building. You now will keep building until you hit "Page Down".
Why is this useful? It lets you start building a resource tower (or welding a CC, or anything else that requires you to hold down your Use key for an obnoxious period of time) and keep building it while having both hands free to type. Especially useful for gorges, since you can type out updates about your building plans while you're actually building.
(An alternative that I've heard of is to bind your Use key to something like Enter so it won't conflict with anything you might want to type in chat, but I find that makes it too difficult to build an offense chamber during combat.)
Funny how I learned almost all that by myself ¬_¬