|
|
| Line 1: |
Line 1: |
| Con files are the core of how Battlefield 2 (and 1942 before it) configures its weapons, maps, objects, players and other game assets. With Battlefield 2, the con grammar has extended into a rudimentry scripting language, with loops and full conditionals. Battlefield 1942 had only very rudimentry conditionals.
| | #REDIRECT [[Console_Script_Grammar]] |
| | |
| __TOC__
| |
| | |
| | |
| | |
| == Comments ==
| |
| | |
| There exist two classes of comments, block:
| |
| | |
| <pre>
| |
| beginRem
| |
| this text is ignored
| |
| endRem
| |
| </pre>
| |
| | |
| and line:
| |
| | |
| <pre> rem this text is ignored </pre>
| |
| | |
| == Statements ==
| |
| | |
| Statements are a command followed by a number of optionally "quoted", whitespace-seperated arguments. The number of arguments may be variable or strictly limited by the command in use. The available commands is beyond the scope of this page, but a good portion of them are included with the editor. A full list is available by running GNU <code>strings</code> against your bf2.exe ;)
| |
| | |
| == Variables ==
| |
| | |
| Variables must be predefined, and have a strict naming system. All mutable variables must begin with <code>v_</code> whereas all immutable variables or ''constants'' must begin with <code>c_</code>. It's a simple form of [http://en.wikipedia.org/wiki/Hungarian_Notation wikipedia:Hungarian Notation].
| |
| | |
| === Mutable Variables ===
| |
| | |
| The code:
| |
| | |
| <pre> var v_dongs = test </pre>
| |
| | |
| Defines a new variable called ''dongs'' or ''v_dongs'' depending on your point of view with the value "test". When defining a variable you can omit the default value however:
| |
| | |
| <pre> var v_dongs </pre>
| |
| | |
| is a value construct for example.
| |
| | |
| === Immutable Variables ===
| |
| | |
| <pre> const c_butts = test </pre>
| |
| | |
| Defines a constant called, again, ''butts'' or ''c_butts'' with the value "test". Obviously, this variable cannot be changed.
| |
| | |
| === <code>const</code> vs. <code>var</code> and assignments ===
| |
| | |
| Assigning to a variable is as simple as appending <code> -> v_varname</code> to any command. However, many commands do not return a value. The ones that do generally return either a boolean value (<code>0</code> or <code>1</code>) or a simple string.
| |
| | |
| Clearly, trying to assign to a <code>const</code> variable is an error and will not work.
| |
| | |
| == Conditionals ==
| |
| | |
| Conditionals include the standard <code>if ... endIf</code>, <code>if ... elseIf ... endIf</code> and <code>while ... endWhile</code> constructs. These evaluate an ''expression''.
| |
| | |
| === Expressions ===
| |
| | |
| The grammar of an expression is roughly:
| |
| | |
| <pre> <variable> <comparator> <value> </pre>
| |
| | |
| Where
| |
| | |
| * ''variable'' is any variable name beginning with <code>v_</code> or <code>c_</code>.
| |
| * ''comparator'' is one of <code>==</code>, <code>!=</code>, <code>></code>, <code>>=</code>, <code><</code> or <code><=</code> or their textual equivalents: <code>lessOrEqualThan</code>, <code>lessThan</code>, <code>greaterOrEqualThan</code>, <code>greaterThan</code>, <code>notEquals</code>, <code>equals</code>.
| |
| * ''value'' is any literal string, quoted if neccessary.
| |
| | |
| == Return ==
| |
| | |
| You may cease interpretation of the current .con file by using the command <code>return</code>. This resumes interpretation from the calling file. It is an error to use this unless the file was called with...
| |
| | |
| == <code>include</code> and <code>run</code> ==
| |
| | |
| <code>include</code> and <code>run</code> do similar things and may in fact be identical. These trigger the interpretation of another .con file. They also have the ability to set ''arguments'', which are a special type of mutable variable. For example:
| |
| | |
| <pre> run test.con 1 2 3 </pre>
| |
| | |
| Runs test.con. In test.con, the variables <code>v_arg1</code>, <code>v_arg2</code> and <code>v_arg3</code> are set to <code>1</code>, <code>2</code> and <code>3</code> respectively. Typically this is used along with a conditional to do something for the editor mode, or to do something different for single player mode (a common use in BF1942, where this method also existed).
| |
| | |
| == An Example ==
| |
| | |
| <pre>
| |
| var v_tst
| |
| fileManager.fileExists movies/menu.bik -> v_tst
| |
| if v_tst == 0
| |
| fileManager.copyFile ../../mods/bf2/movies/menu.bik movies/menu.bik
| |
| fileManager.copyFile ../../mods/bf2/movies/menu_loggedin.bik movies/menu_loggedin.bik
| |
| endIf
| |
| </pre>
| |
| | |
| This example checks if movies/menu.bik exists, and if it doesn't copies two files from the <code>bf2</code> mod to the current mod.
| |