Serc – User
mNo edit summary |
Lou Montana (talk | contribs) m (Text replacement - "<code>" to "<code style="display: block">") |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
ATTENTION! This is far from being valuable information for anyone but contributors. | ATTENTION! This is far from being valuable information for anyone but contributors. | ||
==Syntax== | == Syntax == | ||
Classes could be compared to folders. There is a folder for every object in ArmA. In every folder there are files which we will call attributes. A class definition with an attribute will look like this: | |||
<code style="display: block">class name { | |||
attribute = value; | |||
}; | |||
</code> | |||
There could also be an array of attributes. | |||
<code style="display: block">class name { | |||
attribute = value; | |||
attributeArray[] = {value1,value2,value3}; | |||
};</code> | |||
<code>class | There can't be two same classnames in a config. For example | ||
<code style="display: block">class test { | |||
attribute = value; | |||
}; | |||
class test { | |||
attribute = value; | attribute = value; | ||
}; | }; | ||
</code> | </code> | ||
will NOT work! | |||
<code> | Same goes for two definitions of an attribute in one class. | ||
class | <code style="display: block">class test { | ||
attribute = value; | |||
attribute = value; | |||
};</code> | |||
Will not work! | |||
== Inheritance == | |||
With inheritance you can create a dependency of a object to a parent object. This saves you a lot of typing and makes it easier to maintain. A parent class is usually a generalisation. A Stryker for example is an APC and an APC is a ground vehicle. | |||
We can inherit from another class by adding ''': className''' to our class. But the class needs to be present in the config. Like here: | |||
<code style="display: block">class parentClass { | |||
attribute = value; | attribute = value; | ||
}; | |||
class childClass : parentClass { | |||
anotherAttribue = anotherValue; | |||
};</code> | };</code> | ||
<code>class parentClass; | If it is not present, we can reference it. Note the missing {}. | ||
<code style="display: block">'''class parentClass;''' | |||
class childClass : parentClass { | class childClass : parentClass { | ||
additionalAttribute = value; | additionalAttribute = value; | ||
};</code> | };</code> | ||
Attributes from parent classes can easily be redefined (which is different from overwritten). | |||
<code><nowiki>class parentClass { | <code style="display: block"><nowiki>class parentClass { | ||
parentAttribute = value; | parentAttribute = value; | ||
}; | }; | ||
Line 38: | Line 62: | ||
</code> | </code> | ||
==Commenting== | == Commenting == | ||
===Line Comment=== | === Line Comment === | ||
A line comment is initiated by '''//''' and lasts until the end of the line. Comments are ignored at runtime, so there can be anything in there, including valid code which should not be used. | |||
//i am a comment | //i am a comment | ||
Line 46: | Line 71: | ||
// commentedAttribute = commentedValue | // commentedAttribute = commentedValue | ||
===Block Comment=== | === Block Comment === | ||
<code>/* i an a comment block <br> | A block comment is initiated by '''/*''' and lasts until the next '''*/'''. It can comment out multiple lines or less than a line. | ||
<code style="display: block">/* i an a comment block <br> | |||
and it works over multiple lines <br> | and it works over multiple lines <br> | ||
until its over */</code> | until its over */</code> | ||
<code>notCommentedAttribute = /* commentedValue */ notCommentedValue;</code> | <code style="display: block">notCommentedAttribute = /* commentedValue */ notCommentedValue;</code> | ||
==Formatting== | == Formatting == | ||
The layout and format is a matter of taste. The best formatting is the formatting which suits you best. It is advisable to make it as easily readable as possible by using a lot of whitespaces like linebreaks and indents. The examples 1 and 2 use a lot of whitespace but are easily readable while example 3 is remarkably shorter and much less readable. Especially with multiple attributes this gets confusing. | |||
=== | === Example 1 === | ||
<code>class name { | <code style="display: block">class name { | ||
attribute = value; | attribute = value; | ||
}; | }; | ||
</code> | </code> | ||
=== | === Example 2 === | ||
<code>class name | <code style="display: block">class name | ||
{ | { | ||
attribute = value; | attribute = value; | ||
};</code> | };</code> | ||
=== | === Example 3 === | ||
<code>class name {attribute1 = value;};</code> | <code style="display: block">class name {attribute1 = value;};</code> | ||
==Preprocessor Commands== | == Preprocessor Commands == | ||
===define=== | Preprocessor commands are processed before the config has been used. | ||
=== define === | |||
The command define allows you to use variables in a config. | |||
Syntax: | Syntax: | ||
#define variableName value | #define variableName value | ||
Usage: | Usage: | ||
<code><nowiki>#define BASE_COLOR {0,0,0,0} | <code style="display: block"><nowiki>#define BASE_COLOR {0,0,0,0} | ||
class button { | class button { | ||
backgroundColor = BASE_COLOR; | backgroundColor[] = BASE_COLOR; | ||
};</nowiki></code> | };</nowiki></code> | ||
===include=== | |||
=== include === | |||
This command merges another file into the file with this command. Allowed formats are .h and .hpp. | |||
Syntax: | Syntax: | ||
#include "path\to\file.hpp"; | #include "path\to\file.hpp"; | ||
==Example Config== | == Example Config == | ||
<code><nowiki> | <code style="display: block"><nowiki> | ||
class cfgPatches { | class cfgPatches { | ||
class PBONAME { | class PBONAME { | ||
requiredVersion = 1.0; // requires | requiredVersion = 1.0; // requires Arma 2 version 1.0 | ||
}; | }; | ||
}; | }; |
Latest revision as of 11:52, 11 January 2023
Basic Config File
ATTENTION! This is far from being valuable information for anyone but contributors.
Syntax
Classes could be compared to folders. There is a folder for every object in ArmA. In every folder there are files which we will call attributes. A class definition with an attribute will look like this:
class name {
attribute = value;
};
There could also be an array of attributes.
class name {
attribute = value;
attributeArray[] = {value1,value2,value3};
};
There can't be two same classnames in a config. For example
class test {
attribute = value;
};
class test {
attribute = value;
};
will NOT work!
Same goes for two definitions of an attribute in one class.
class test {
attribute = value;
attribute = value;
};
Will not work!
Inheritance
With inheritance you can create a dependency of a object to a parent object. This saves you a lot of typing and makes it easier to maintain. A parent class is usually a generalisation. A Stryker for example is an APC and an APC is a ground vehicle.
We can inherit from another class by adding : className to our class. But the class needs to be present in the config. Like here:
class parentClass {
attribute = value;
};
class childClass : parentClass {
anotherAttribue = anotherValue;
};
If it is not present, we can reference it. Note the missing {}.
class parentClass;
class childClass : parentClass {
additionalAttribute = value;
};
Attributes from parent classes can easily be redefined (which is different from overwritten).
class parentClass {
parentAttribute = value;
};
class childClass : parentClass {
parentAttribute = newValue;
};
Commenting
Line Comment
A line comment is initiated by // and lasts until the end of the line. Comments are ignored at runtime, so there can be anything in there, including valid code which should not be used.
//i am a comment
notCommentedAttribute = notCommentedValue; // commented
// commentedAttribute = commentedValue
Block Comment
A block comment is initiated by /* and lasts until the next */. It can comment out multiple lines or less than a line.
/* i an a comment block
and it works over multiple lines
until its over */
notCommentedAttribute = /* commentedValue */ notCommentedValue;
Formatting
The layout and format is a matter of taste. The best formatting is the formatting which suits you best. It is advisable to make it as easily readable as possible by using a lot of whitespaces like linebreaks and indents. The examples 1 and 2 use a lot of whitespace but are easily readable while example 3 is remarkably shorter and much less readable. Especially with multiple attributes this gets confusing.
Example 1
class name {
attribute = value;
};
Example 2
class name
{
attribute = value;
};
Example 3
class name {attribute1 = value;};
Preprocessor Commands
Preprocessor commands are processed before the config has been used.
define
The command define allows you to use variables in a config. Syntax:
#define variableName value
Usage:
#define BASE_COLOR {0,0,0,0}
class button {
backgroundColor[] = BASE_COLOR;
};
include
This command merges another file into the file with this command. Allowed formats are .h and .hpp. Syntax:
#include "path\to\file.hpp";
Example Config
class cfgPatches {
class PBONAME {
requiredVersion = 1.0; // requires Arma 2 version 1.0
};
};
class cfgVehicles {
class SoldierWB; // a basic soldier class in ArmA
class someNewSoldier : SoldierWB {
displayName = "Rambo";
};
};