NOTICE: The wiki has undergone updates and everything is running smoothly. I am still working on the CSS so there are a few minor visual kinks.
Console Scripting
From JAWiki
JA Console scripting is a pretty straightforward process. You're basically just defining sequences of commands that will be sent to the console. It helps to have a good understanding of what you're working with. Basically, you can only do 2 things in a CFG file: Run commands, and set cvar values. Both of these are referred to generically as statements.
Contents |
[edit] Commands
You're probably familiar with commands, these are issued to the console to tell the game to do something. Common commands are bind, connect, quit, etc.
See the Commands page for more information.
[edit] CVars
CVar stands for Console Variable, and basically refers to the settings that you can configure through the console. Example CVars are name, sensitivity, cg_thirdpersoncameradamp 0, etc.
See the Cvars page for more information.
[edit] VStr
A vstr is a virtual string, this is the data type available for use by console users, and replaced the alias command used in previous Quake engines. Your vstr can contain a sequence of commands or cvar settings to be run when the vstr is evaluated. You can define a vstr using the set command, or a variation of it. After a vstr has been set, its value can be evaluated by issuing \vstr <vstr name> to the console.
[edit] Special Commands
There are some commands that are particularly useful for console scripting.
- set - As mentioned in the VStr section, set and its variants are used to define a vstr.
- vstr - this command is used to evaluate a vstr.
- bind - this command is used to bind a key.
- exec - this command will load a specified file and run any commands therein.
- wait - wait for a game tic to pass before continuing, can be longer by specifying a number, such as wait 5
- toggle - changes boolean cvars to the opposite state. For instance toggle cg_drawfps will turn the FPS display on or off.
[edit] Syntax
The syntax for CFG scripts is pretty simple.
- When issuing arguments, you should usually enclose the value in quotation marks, although this is only required when it contains spaces or multiple commands or cvars.
- When you're setting multiple statements in one line or to a single vstr, the statements should be separated by a semicolon (;).
- Any lines that begin with two forward slashes (//) will be ignored. Use this to write comments within your script file.
- Commands and CVars are case-insensitive.
- Statements can only be on a single line, but spacing on that line does not matter.
When using the set command, you are telling the console to create a virtual string with the name and value that you provide. That string will usually be a sequence of commands and cvar assignments that you want to be performed later. Additionally, vstrs can contain references to other vstrs, allowing you to break your script into smaller, more flexible units.
[edit] Examples
Say you want to have one button to toggle between two different actions. We will make a vstr called "twoActions" alternate between two actions each time it is used.
// To start off, we first want twoActions to do the first action set twoActions "vstr firstAction" // Here define what will actuallly happen the first time the button is pressed. // Note that at the end we set twoActions vstr to do second Action next time. set firstAction "do first action; set twoActions secondAction" // Now we define what the second action will be, and reset twoActions to point to firstAction again. set secondAction "do second action; set twoActions firstAction" // finally, we bind a key to the twoActions vstr bind x "vstr twoActions"
Some people new to scripting will not create the twoActions vstr in the above example, and instead just switch the vstr that x is binded to. This is not advised, because it means the binded key cannot be changed easily, and you won't have a single vstr that you can use from the console.
Categories: Game Basics | Misc | Extensions | Console | CFG Scripts
