use the same code highlighting blocks everywhere (#8591)

`cpp` instead of `c++` or `js`
This commit is contained in:
Jo David 2021-10-23 18:39:02 +02:00 committed by GitHub
parent 6abc4af3f6
commit 2375529321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 54 deletions

View File

@ -181,7 +181,7 @@ This ensures every function starts off in an uniform way and enforces function d
### 3.2 Headers ### 3.2 Headers
Every function should have a header of the following format appear before any code: Every function should have a header of the following format appear before any code:
```js ```cpp
/* /*
* Author: [Name of Author(s)] * Author: [Name of Author(s)]
* [Description] * [Description]
@ -260,7 +260,7 @@ class Something : Or {
When using `if`/`else`, it is encouraged to put `else` on the same line as the closing brace to save space: When using `if`/`else`, it is encouraged to put `else` on the same line as the closing brace to save space:
```js ```cpp
if (alive player) then { if (alive player) then {
player setDamage 1; player setDamage 1;
} else { } else {
@ -284,7 +284,7 @@ Every new scope should be on a new indent. This will make the code easier to und
Good: Good:
```js ```cpp
call { call {
call { call {
if (/* condition */) then { if (/* condition */) then {
@ -296,7 +296,7 @@ call {
Bad: Bad:
```js ```cpp
call { call {
call { call {
if (/* condition */) then { if (/* condition */) then {
@ -311,7 +311,7 @@ Inline comments should use `//`. Usage of `/* */` is allowed for larger comment
Example: Example:
```js ```cpp
//// Comment // < incorrect //// Comment // < incorrect
// Comment // < correct // Comment // < correct
/* Comment */ // < correct /* Comment */ // < correct
@ -324,7 +324,7 @@ Comments within the code shall be used when they are describing a complex and cr
Good: Good:
```js ```cpp
// find the object with the most blood loss // find the object with the most blood loss
_highestObj = objNull; _highestObj = objNull;
_highestLoss = -1; _highestLoss = -1;
@ -338,28 +338,28 @@ _highestLoss = -1;
Good: Good:
```js ```cpp
// Check if the unit is an engineer // Check if the unit is an engineer
(_obj getvariable [QGVAR(engineerSkill), 0] >= 1); (_obj getvariable [QGVAR(engineerSkill), 0] >= 1);
``` ```
Bad: Bad:
```js ```cpp
// Get the engineer skill and check if it is above 1 // Get the engineer skill and check if it is above 1
(_obj getvariable [QGVAR(engineerSkill), 0] >= 1); (_obj getvariable [QGVAR(engineerSkill), 0] >= 1);
``` ```
Bad: Bad:
```js ```cpp
// Get the variable myValue from the object // Get the variable myValue from the object
_myValue = _obj getvariable [QGVAR(myValue), 0]; _myValue = _obj getvariable [QGVAR(myValue), 0];
``` ```
Bad: Bad:
```js ```cpp
// Loop through all units to increase the myvalue variable // Loop through all units to increase the myvalue variable
{ {
_x setvariable [QGVAR(myValue), (_x getvariable [QGVAR(myValue), 0]) + 1]; _x setvariable [QGVAR(myValue), (_x getvariable [QGVAR(myValue), 0]) + 1];
@ -369,19 +369,19 @@ Bad:
### 5.5 Brackets around code ### 5.5 Brackets around code
When making use of brackets `( )`, use as few as possible, unless doing so decreases readability of the code. Avoid statements such as: When making use of brackets `( )`, use as few as possible, unless doing so decreases readability of the code. Avoid statements such as:
```js ```cpp
if (!(_value)) then { }; if (!(_value)) then { };
``` ```
However the following is allowed: However the following is allowed:
```js ```cpp
_value = (_array select 0) select 1; _value = (_array select 0) select 1;
``` ```
Any conditions in statements shall always be wrapped around brackets. Any conditions in statements shall always be wrapped around brackets.
```js ```cpp
if (!_value) then {}; if (!_value) then {};
if (_value) then {}; if (_value) then {};
``` ```
@ -402,14 +402,14 @@ When using array notation `[]`, always use a space between elements to improve c
Good: Good:
```js ```cpp
params ["_unit", "_vehicle"]; params ["_unit", "_vehicle"];
private _pos = [0, 0, 0]; private _pos = [0, 0, 0];
``` ```
Bad: Bad:
```js ```cpp
params ["_unit","_vehicle"]; params ["_unit","_vehicle"];
private _pos = [0,0,0]; private _pos = [0,0,0];
``` ```
@ -436,19 +436,19 @@ All private variables shall make use of the `private` keyword on initialization.
Good: Good:
```js ```cpp
private _myVariable = "hello world"; private _myVariable = "hello world";
``` ```
Good: Good:
```js ```cpp
_myArray params ["_elementOne", "_elementTwo"]; _myArray params ["_elementOne", "_elementTwo"];
``` ```
Bad: Bad:
```js ```cpp
_elementOne = _myArray select 0; _elementOne = _myArray select 0;
_elementTwo = _myArray select 1; _elementTwo = _myArray select 1;
``` ```
@ -461,7 +461,7 @@ Declarations should be at the smallest feasible scope.
Good: Good:
```js ```cpp
if (call FUNC(myCondition)) then { if (call FUNC(myCondition)) then {
private _areAllAboveTen = true; // <- smallest feasable scope private _areAllAboveTen = true; // <- smallest feasable scope
@ -479,7 +479,7 @@ if (call FUNC(myCondition)) then {
Bad: Bad:
```js ```cpp
private _areAllAboveTen = true; // <- this is bad, because it can be initialized in the if statement private _areAllAboveTen = true; // <- this is bad, because it can be initialized in the if statement
if (call FUNC(myCondition)) then { if (call FUNC(myCondition)) then {
{ {
@ -499,7 +499,7 @@ Private variables will not be introduced until they can be initialized with mean
Good: Good:
```js ```cpp
private _myVariable = 0; // good because the value will be used private _myVariable = 0; // good because the value will be used
{ {
_x params ["_value", "_amount"]; _x params ["_value", "_amount"];
@ -511,7 +511,7 @@ private _myVariable = 0; // good because the value will be used
Bad: Bad:
```js ```cpp
private _myvariable = 0; // Bad because it is initialized with a zero, but this value does not mean anything private _myvariable = 0; // Bad because it is initialized with a zero, but this value does not mean anything
if (_condition) then { if (_condition) then {
_myVariable = 1; _myVariable = 1;
@ -522,7 +522,7 @@ if (_condition) then {
Good: Good:
```js ```cpp
private _myvariable = [1, 2] select _condition; private _myvariable = [1, 2] select _condition;
``` ```
@ -537,20 +537,20 @@ When using `getVariable`, there shall either be a default value given in the sta
Bad: Bad:
```js ```cpp
_return = obj getvariable "varName"; _return = obj getvariable "varName";
if (isnil "_return") then {_return = 0 }; if (isnil "_return") then {_return = 0 };
``` ```
Good: Good:
```js ```cpp
_return = obj getvariable ["varName", 0]; _return = obj getvariable ["varName", 0];
``` ```
Good: Good:
```js ```cpp
_return = obj getvariable "varName"; _return = obj getvariable "varName";
if (isnil "_return") exitwith {}; if (isnil "_return") exitwith {};
``` ```
@ -560,27 +560,27 @@ Global variables should not be used to pass along information from one function
Bad: Bad:
```js ```cpp
fnc_example = { fnc_example = {
hint GVAR(myVariable); hint GVAR(myVariable);
}; };
``` ```
```js ```cpp
GVAR(myVariable) = "hello my variable"; GVAR(myVariable) = "hello my variable";
call fnc_example; call fnc_example;
``` ```
Good: Good:
```js ```cpp
fnc_example = { fnc_example = {
params ["_content"]; params ["_content"];
hint _content; hint _content;
}; };
``` ```
```js ```cpp
["hello my variable"] call fnc_example; ["hello my variable"] call fnc_example;
``` ```
@ -625,7 +625,7 @@ More information on the [CBA Events System](https://github.com/CBATeam/CBA_A3/wi
**Warning about BIS event handlers:** **Warning about BIS event handlers:**
BIS's event handlers (`addEventHandler`, `addMissionEventHandler`) are slow when passing a large code variable. Use a short code block that calls the function you want. BIS's event handlers (`addEventHandler`, `addMissionEventHandler`) are slow when passing a large code variable. Use a short code block that calls the function you want.
```js ```cpp
player addEventHandler ["Fired", FUNC(handleFired)]; // bad player addEventHandler ["Fired", FUNC(handleFired)]; // bad
player addEventHandler ["Fired", {call FUNC(handleFired)}]; // good player addEventHandler ["Fired", {call FUNC(handleFired)}]; // good
``` ```
@ -638,7 +638,7 @@ Hashes are a variable type that store key value pairs. They are not implemented
The following example is a simple usage using our macros which will be explained further below. The following example is a simple usage using our macros which will be explained further below.
```js ```cpp
_hash = HASHCREATE; _hash = HASHCREATE;
HASH_SET(_hash,"key","value"); HASH_SET(_hash,"key","value");
if (HASH_HASKEY(_hash,"key")) then { if (HASH_HASKEY(_hash,"key")) then {
@ -664,7 +664,7 @@ A description of the above macros is below.
A hashlist is an extension of a hash. It is a list of hashes! The reason for having this special type of storage container rather than using a normal array is that an array of normal hashes that are similar will duplicate a large amount of data in their storage of keys. A hashlist on the other hand uses a common list of keys and an array of unique value containers. The following will demonstrate its usage. A hashlist is an extension of a hash. It is a list of hashes! The reason for having this special type of storage container rather than using a normal array is that an array of normal hashes that are similar will duplicate a large amount of data in their storage of keys. A hashlist on the other hand uses a common list of keys and an array of unique value containers. The following will demonstrate its usage.
```js ```cpp
_defaultKeys = ["key1", "key2", "key3"]; _defaultKeys = ["key1", "key2", "key3"];
// create a new hashlist using the above keys as default // create a new hashlist using the above keys as default
_hashList = HASHLIST_CREATELIST(_defaultKeys); _hashList = HASHLIST_CREATELIST(_defaultKeys);
@ -712,19 +712,19 @@ When adding new elements to an array, `pushBack` shall be used instead of the bi
Good: Good:
```js ```cpp
_a pushBack _value; _a pushBack _value;
``` ```
Also good: Also good:
```js ```cpp
_a append [1, 2, 3]; _a append [1, 2, 3];
``` ```
Bad: Bad:
```js ```cpp
_a set [ count _a, _value]; _a set [ count _a, _value];
_a = a + _[value]; _a = a + _[value];
``` ```
@ -742,14 +742,14 @@ Where possible `[0, 0, 0]` position shall be used, except on `#` objects (e.g. `
This code requires ~1.00ms and will be higher with more objects near wanted position: This code requires ~1.00ms and will be higher with more objects near wanted position:
```js ```cpp
_vehicle = _type createVehicleLocal _posATL; _vehicle = _type createVehicleLocal _posATL;
_vehicle setposATL _posATL; _vehicle setposATL _posATL;
``` ```
While this one requires ~0.04ms: While this one requires ~0.04ms:
```js ```cpp
_vehicle = _type createVehicleLocal [0, 0, 0]; _vehicle = _type createVehicleLocal [0, 0, 0];
_vehicle setposATL _posATL; _vehicle setposATL _posATL;
``` ```
@ -765,13 +765,13 @@ When checking if an array is empty `isEqualTo` shall be used.
### 8.7 `for` Loops ### 8.7 `for` Loops
```js ```cpp
for "_y" from # to # step # do { ... } for "_y" from # to # step # do { ... }
``` ```
shall be used instead of shall be used instead of
```js ```cpp
for [{ ... },{ ... },{ ... }] do { ... }; for [{ ... },{ ... },{ ... }] do { ... };
``` ```
@ -782,7 +782,7 @@ While is only allowed when used to perform a unknown finite amount of steps with
Good: Good:
```js ```cpp
_original = _obj getvariable [QGVAR(value), 0]; _original = _obj getvariable [QGVAR(value), 0];
while {_original < _weaponThreshold} do { while {_original < _weaponThreshold} do {
_original = [_original, _weaponClass] call FUNC(getNewValue); _original = [_original, _weaponClass] call FUNC(getNewValue);
@ -791,7 +791,7 @@ while {_original < _weaponThreshold} do {
Bad: Bad:
```js ```cpp
while {true} do { while {true} do {
// anything // anything
}; };
@ -799,7 +799,7 @@ while {true} do {
### 8.9 `waitUntil` ### 8.9 `waitUntil`
The `waitUntil` command shall not be used. Instead, make use of CBA's `CBA_fnc_waitUntilAndExecute` The `waitUntil` command shall not be used. Instead, make use of CBA's `CBA_fnc_waitUntilAndExecute`
```js ```cpp
[{ [{
params ["_unit"]; params ["_unit"];
_unit getVariable [QGVAR(myVariable), false] _unit getVariable [QGVAR(myVariable), false]

View File

@ -189,7 +189,7 @@ Feel free to tweak the values of the settings to adjust it to your likings.
#### 2.1.1 Preset 1 #### 2.1.1 Preset 1
```c++ ```cpp
force ace_medical_fatalDamageSource = 1; // Sum of Trauma death condition force ace_medical_fatalDamageSource = 1; // Sum of Trauma death condition
force ace_medical_AIDamageThreshold = 0.2; // Decreased AI damage threshold so AI dies in single headshot and few torso taps depending on vest force ace_medical_AIDamageThreshold = 0.2; // Decreased AI damage threshold so AI dies in single headshot and few torso taps depending on vest
force ace_medical_playerDamageThreshold = 3.5; // Increased damage threshold for players, high caliber weapons should still be fatal force ace_medical_playerDamageThreshold = 3.5; // Increased damage threshold for players, high caliber weapons should still be fatal
@ -202,7 +202,7 @@ force ace_medical_statemachine_cardiacArrestTime = 630;
#### 2.1.2 "Basic" Preset #### 2.1.2 "Basic" Preset
```c++ ```cpp
force ace_medical_AIDamageThreshold = 0.2; // Decreased AI damage threshold so AI dies in single headshot and few torso taps depending on vest force ace_medical_AIDamageThreshold = 0.2; // Decreased AI damage threshold so AI dies in single headshot and few torso taps depending on vest
force ace_medical_playerDamageThreshold = 3.5; // Increased damage threshold for players, high caliber weapons should still be fatal force ace_medical_playerDamageThreshold = 3.5; // Increased damage threshold for players, high caliber weapons should still be fatal
force ace_medical_bleedingCoefficient = 0.25; force ace_medical_bleedingCoefficient = 0.25;
@ -217,7 +217,7 @@ force ace_medical_treatment_advancedMedication = false; // Disabled advanced med
#### 2.1.3 "Advanced" Preset #### 2.1.3 "Advanced" Preset
```c++ ```cpp
force ace_medical_fractures = 1; // Splints Fully Heal Fractures - set to "2" to keep sprinting disabled after fracture force ace_medical_fractures = 1; // Splints Fully Heal Fractures - set to "2" to keep sprinting disabled after fracture
force ace_medical_limping = 1; // Limp on Open Wounds force ace_medical_limping = 1; // Limp on Open Wounds
force ace_medical_spontaneousWakeUpChance = 0.15; // 15% chance of waking up from unconscious after stable force ace_medical_spontaneousWakeUpChance = 0.15; // 15% chance of waking up from unconscious after stable
@ -245,7 +245,7 @@ force ace_medical_treatment_medicSurgicalKit = 1; // Medics can stitch
#### 2.2.1 Preset 1 #### 2.2.1 Preset 1
```c++ ```cpp
force ace_medical_fatalDamageSource = 1; // Sum of Trauma death condition force ace_medical_fatalDamageSource = 1; // Sum of Trauma death condition
force ace_medical_feedback_painEffectType = 2; // Forced pain effect type to ensure that everyone is handicapped in the same way force ace_medical_feedback_painEffectType = 2; // Forced pain effect type to ensure that everyone is handicapped in the same way
force ace_medical_spontaneousWakeUpChance = 0.15; // don't let players wake up too fast force ace_medical_spontaneousWakeUpChance = 0.15; // don't let players wake up too fast

View File

@ -15,6 +15,6 @@ version:
Pick-up interaction can be disabled for ammo (e.g. chemlights) attached to an object. Pick-up interaction can be disabled for ammo (e.g. chemlights) attached to an object.
```js ```cpp
OBJECT setVariable ["ace_advanced_throwing_disablePickUp", true, true]; OBJECT setVariable ["ace_advanced_throwing_disablePickUp", true, true];
``` ```

View File

@ -228,7 +228,7 @@ Calls a globally synchronized event, which will also be run on JIP players unles
### 3.4 Example ### 3.4 Example
```js ```cpp
// Event handler added on a target machine // Event handler added on a target machine
["ace_interact_tapShoulder", ace_example_fnc_onTapShoulder] call CBA_fnc_addEventHandler; ["ace_interact_tapShoulder", ace_example_fnc_onTapShoulder] call CBA_fnc_addEventHandler;

View File

@ -47,7 +47,7 @@ To enable other units to move them reference [Scripting](#allow-units-to-move-ra
To change the texture of the flag use the following line on the rally point object: To change the texture of the flag use the following line on the rally point object:
```js ```cpp
this setFlagTexture 'path\to\my\texture\my_awesome_clan_logo.paa'; this setFlagTexture 'path\to\my\texture\my_awesome_clan_logo.paa';
``` ```
@ -55,6 +55,6 @@ this setFlagTexture 'path\to\my\texture\my_awesome_clan_logo.paa';
To enable other units to move rally points, such as JIP units, use the following line on the units: To enable other units to move rally points, such as JIP units, use the following line on the units:
```js ```cpp
_unit setVariable ["ACE_canMoveRallypoint", true, true]; _unit setVariable ["ACE_canMoveRallypoint", true, true];
``` ```

View File

@ -26,6 +26,6 @@ The module settings define which side a player can control or how big the radius
To enable a player to control AI execute the following on it: To enable a player to control AI execute the following on it:
```js ```cpp
this setVariable ["ACE_CanSwitchUnits", true]; this setVariable ["ACE_CanSwitchUnits", true];
``` ```

View File

@ -52,7 +52,7 @@ Sync the module with vehicles and players. Custom keys will be handed to players
To override a vehicle's side, allowing locking and unlocking using a different side's key, use the following on that vehicle (use wanted side instead of `west`): To override a vehicle's side, allowing locking and unlocking using a different side's key, use the following on that vehicle (use wanted side instead of `west`):
```js ```cpp
this setVariable ["ace_vehiclelock_lockSide", west]; this setVariable ["ace_vehiclelock_lockSide", west];
``` ```
@ -60,6 +60,6 @@ this setVariable ["ace_vehiclelock_lockSide", west];
To override default lock pick strength for a vehicle, that is how long lock picking will take, use the following on that vehicle (use wanted time in seconds instead of `5`): To override default lock pick strength for a vehicle, that is how long lock picking will take, use the following on that vehicle (use wanted time in seconds instead of `5`):
```js ```cpp
this setVariable ["ace_vehiclelock_lockpickStrength", 5]; this setVariable ["ace_vehiclelock_lockpickStrength", 5];
``` ```