Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace CPP highlighting with SQF highlighting #8656

Merged
merged 1 commit into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/wiki/development/arma-3-scheduler-and-our-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ It means we need to live outside of the spawn execution as much as possible. The

The scheduler will also actually halt your script mid-execution, usually at the end of a given control block, and pause you to yield to other scripts. This can lead to drastically incorrect results when performing calculations and unexpected behaviours. For example, try the following code. Even though it doesn't seem logical, it will show a hint.

```cpp
```sqf
myVar = true;
0 spawn {
while {true} do {
Expand Down Expand Up @@ -90,22 +90,22 @@ These rules follow from the rules of thumb above:
#### 3.3.1 Per Frame Handler
See: [https://github.com/CBATeam/CBA_A3/blob/master/addons/common/fnc_addPerFrameHandler.sqf](https://github.com/CBATeam/CBA_A3/blob/master/addons/common/fnc_addPerFrameHandler.sqf) for more details.

```cpp
```sqf
[{code} , delay, [params]] call CBA_fnc_addPerFrameHandler;
```


#### 3.3.2 WaitAndExecute
See: [https://github.com/CBATeam/CBA_A3/blob/master/addons/common/fnc_waitAndExecute.sqf](https://github.com/CBATeam/CBA_A3/blob/master/addons/common/fnc_waitAndExecute.sqf) for more details.

```cpp
```sqf
[{delayed code}, [params], delay] call CBA_fnc_waitAndExecute;
```


#### 3.3.3 WaitUntilAndExecute
See: [https://github.com/CBATeam/CBA_A3/blob/master/addons/common/fnc_waitUntilAndExecute.sqf](https://github.com/CBATeam/CBA_A3/blob/master/addons/common/fnc_waitUntilAndExecute.sqf) for more details.

```cpp
```sqf
[{condition}, {code}, [params]] call CBA_fnc_waitUntilAndExecute;
```
88 changes: 44 additions & 44 deletions docs/wiki/development/coding-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ This ensures every function starts off in an uniform way and enforces function d
### 3.2 Headers
Every function should have a header of the following format appear before any code:

```cpp
```sqf
/*
* Author: [Name of Author(s)]
* [Description]
Expand Down Expand Up @@ -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:

```cpp
```sqf
if (alive player) then {
player setDamage 1;
} else {
Expand All @@ -284,7 +284,7 @@ Every new scope should be on a new indent. This will make the code easier to und

Good:

```cpp
```sqf
call {
call {
if (/* condition */) then {
Expand All @@ -296,7 +296,7 @@ call {

Bad:

```cpp
```sqf
call {
call {
if (/* condition */) then {
Expand All @@ -311,7 +311,7 @@ Inline comments should use `//`. Usage of `/* */` is allowed for larger comment

Example:

```cpp
```sqf
//// Comment // < incorrect
// Comment // < correct
/* Comment */ // < correct
Expand All @@ -324,7 +324,7 @@ Comments within the code shall be used when they are describing a complex and cr

Good:

```cpp
```sqf
// find the object with the most blood loss
_highestObj = objNull;
_highestLoss = -1;
Expand All @@ -338,28 +338,28 @@ _highestLoss = -1;

Good:

```cpp
```sqf
// Check if the unit is an engineer
(_obj getvariable [QGVAR(engineerSkill), 0] >= 1);
```

Bad:

```cpp
```sqf
// Get the engineer skill and check if it is above 1
(_obj getvariable [QGVAR(engineerSkill), 0] >= 1);
```

Bad:

```cpp
```sqf
// Get the variable myValue from the object
_myValue = _obj getvariable [QGVAR(myValue), 0];
```

Bad:

```cpp
```sqf
// Loop through all units to increase the myvalue variable
{
_x setvariable [QGVAR(myValue), (_x getvariable [QGVAR(myValue), 0]) + 1];
Expand All @@ -369,19 +369,19 @@ Bad:
### 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:

```cpp
```sqf
if (!(_value)) then { };
```

However the following is allowed:

```cpp
```sqf
_value = (_array select 0) select 1;
```

Any conditions in statements shall always be wrapped around brackets.

```cpp
```sqf
if (!_value) then {};
if (_value) then {};
```
Expand All @@ -402,14 +402,14 @@ When using array notation `[]`, always use a space between elements to improve c

Good:

```cpp
```sqf
params ["_unit", "_vehicle"];
private _pos = [0, 0, 0];
```

Bad:

```cpp
```sqf
params ["_unit","_vehicle"];
private _pos = [0,0,0];
```
Expand All @@ -436,19 +436,19 @@ All private variables shall make use of the `private` keyword on initialization.

Good:

```cpp
```sqf
private _myVariable = "hello world";
```

Good:

```cpp
```sqf
_myArray params ["_elementOne", "_elementTwo"];
```

Bad:

```cpp
```sqf
_elementOne = _myArray select 0;
_elementTwo = _myArray select 1;
```
Expand All @@ -461,7 +461,7 @@ Declarations should be at the smallest feasible scope.

Good:

```cpp
```sqf
if (call FUNC(myCondition)) then {
private _areAllAboveTen = true; // <- smallest feasable scope

Expand All @@ -479,7 +479,7 @@ if (call FUNC(myCondition)) then {

Bad:

```cpp
```sqf
private _areAllAboveTen = true; // <- this is bad, because it can be initialized in the if statement
if (call FUNC(myCondition)) then {
{
Expand All @@ -499,7 +499,7 @@ Private variables will not be introduced until they can be initialized with mean

Good:

```cpp
```sqf
private _myVariable = 0; // good because the value will be used
{
_x params ["_value", "_amount"];
Expand All @@ -511,7 +511,7 @@ private _myVariable = 0; // good because the value will be used

Bad:

```cpp
```sqf
private _myvariable = 0; // Bad because it is initialized with a zero, but this value does not mean anything
if (_condition) then {
_myVariable = 1;
Expand All @@ -522,7 +522,7 @@ if (_condition) then {

Good:

```cpp
```sqf
private _myvariable = [1, 2] select _condition;
```

Expand All @@ -537,20 +537,20 @@ When using `getVariable`, there shall either be a default value given in the sta

Bad:

```cpp
```sqf
_return = obj getvariable "varName";
if (isnil "_return") then {_return = 0 };
if (isnil "_return") then { _return = 0 };
```

Good:

```cpp
```sqf
_return = obj getvariable ["varName", 0];
```

Good:

```cpp
```sqf
_return = obj getvariable "varName";
if (isnil "_return") exitwith {};
```
Expand All @@ -560,27 +560,27 @@ Global variables should not be used to pass along information from one function

Bad:

```cpp
```sqf
fnc_example = {
hint GVAR(myVariable);
};
```

```cpp
```sqf
GVAR(myVariable) = "hello my variable";
call fnc_example;
```

Good:

```cpp
```sqf
fnc_example = {
params ["_content"];
hint _content;
};
```

```cpp
```sqf
["hello my variable"] call fnc_example;
```

Expand Down Expand Up @@ -625,7 +625,7 @@ More information on the [CBA Events System](https://github.com/CBATeam/CBA_A3/wi

**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.
```cpp
```sqf
player addEventHandler ["Fired", FUNC(handleFired)]; // bad
player addEventHandler ["Fired", {call FUNC(handleFired)}]; // good
```
Expand All @@ -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.

```cpp
```sqf
_hash = HASHCREATE;
HASH_SET(_hash,"key","value");
if (HASH_HASKEY(_hash,"key")) then {
Expand All @@ -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.

```cpp
```sqf
_defaultKeys = ["key1", "key2", "key3"];
// create a new hashlist using the above keys as default
_hashList = HASHLIST_CREATELIST(_defaultKeys);
Expand Down Expand Up @@ -712,19 +712,19 @@ When adding new elements to an array, `pushBack` shall be used instead of the bi

Good:

```cpp
```sqf
_a pushBack _value;
```

Also good:

```cpp
```sqf
_a append [1, 2, 3];
```

Bad:

```cpp
```sqf
_a set [ count _a, _value];
_a = a + _[value];
```
Expand All @@ -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:

```cpp
```sqf
_vehicle = _type createVehicleLocal _posATL;
_vehicle setposATL _posATL;
```

While this one requires ~0.04ms:

```cpp
```sqf
_vehicle = _type createVehicleLocal [0, 0, 0];
_vehicle setposATL _posATL;
```
Expand All @@ -765,13 +765,13 @@ When checking if an array is empty `isEqualTo` shall be used.

### 8.7 `for` Loops

```cpp
```sqf
for "_y" from # to # step # do { ... }
```

shall be used instead of

```cpp
```sqf
for [{ ... },{ ... },{ ... }] do { ... };
```

Expand All @@ -782,7 +782,7 @@ While is only allowed when used to perform a unknown finite amount of steps with

Good:

```cpp
```sqf
_original = _obj getvariable [QGVAR(value), 0];
while {_original < _weaponThreshold} do {
_original = [_original, _weaponClass] call FUNC(getNewValue);
Expand All @@ -791,15 +791,15 @@ while {_original < _weaponThreshold} do {

Bad:

```cpp
```sqf
while {true} do {
// anything
};
```

### 8.9 `waitUntil`
The `waitUntil` command shall not be used. Instead, make use of CBA's `CBA_fnc_waitUntilAndExecute`
```cpp
```sqf
[{
params ["_unit"];
_unit getVariable [QGVAR(myVariable), false]
Expand Down