-
-
Notifications
You must be signed in to change notification settings - Fork 157
Standardised Variable Types
Because SQF is a small dynamically typed scripting language, there is no default design in of structures and variable types. I have created this guideline to clear the confusion about how to express variable types for function. The following syntax design is inspired by C# Func<> delegates(Except that name/description is coming after the type).
These names are based on the return of typeName
engine command. Variable names/description go after the the . UPPERCASE capitalisation is not strictly required.
<ARRAY> banList
<BOOL> easyMode
<CODE> crateFiller
<CONFIG> uniformParent
<CONTROL> vehicleBuyMenu
<DISPLAY> currentPlayerMenu
<GROUP> AIPatrol
<LOCATION> village1
<OBJECT> Petros
<SCALAR> chanceOfSuccess
<SCRIPT> waitForSleep
<SIDE> invaders
<STRING> plainMessage
<TEXT> fancyText
<NAMESPACE> storageLocation
<DIARY_RECORD> howToGetStartedGuide
<TASK> defendPetros
<HASHMAP> vehicleEnums
<NIL> Usually used when a function provides no meaningful return.
<ANY> Accepts any type, including nil.
<T> Generic Type
<T#> Generic Type if multiple are required, substitute # with an integer.
Arrays passed to functions are expected contain certain types. Just <ARRAY>
will not provide enough information.
<ARRAY<STRING>> badList
<ARRAY<SCALAR>> weightedSelectionValues
Arrays can be used to pass around structured data. Such as a position, that has to maintain the same order and only 3 values. In this case <ARRAY<SCALAR>>
will not do.
<SCALAR,SCALAR,SCALAR> A position or vector.
<ARRAY<SCALAR,SCALAR,SCALAR>> A list of positions or vectors
<STRING,ANY> A key-value pair.
<ARRAY<STRING,ANY>> A list of key-value pairs
Some structs are common enough that almost everyone working with SQF will know what they are. This can provide a great simplification. PascalCase capitalisation is not strictly required.
<Pos3> A 3D position or vector
<Vec3> A 3D position or vector
<Poss> A 2D position or vector, such as marker positions.
<Vec2> A 2D position or vector, such as marker positions.
<ARRAY<Pos3>> A list of positions or vectors
<KeyPair> A key-value pair
<ARRAY<KeyPair>> A list of key-value pairs
Feel free to add common and strongly defined types here
<Pos#>
A collection of scalars where # represents the number of dimensions: [4,2,0]
<Vec#>
A collection of scalars where # represents the number of dimensions: [4,2,0]
<KeyPair>
A key-value pair. Use in getVariable
, and hashMap getOrDefault x
: ["keyName",someValueOfAnyType]
<Map>
An unordered array of key-value pairs. Use in createHashMapFromArray
: [["key1",value1],["key2",value2]]
<KeyPair<T>>
A key-value pair where all values are of the same defined type.
<Map<T>>
An unordered array of key-value pairs. Values' type are specified: [["key1",0.5],["key2",0.9]]
<UnitLoadout>
https://community.bistudio.com/wiki/Unit_Loadout_Array
Passing code around as delegates is required event handlers and actions. Specifying the parameters and return of code will be useful in it's required in SQF function. In order to shorten and simplify, <>
may be omitted if it is not an unnamed struct. The following syntax is inspired by C# Func<> delegates as C++ delegates are a mess.
_fnc_paired_selectRandom = {
(_this apply {_x#0}) selectRandomWeighted (_this apply {_x#1});
}
If we wanted to accept a matching param and return signature, it could be expressed as:
<CODE<ARRAY<STRING,SCALAR>,STRING> A select random weighted function.
The above function does not care what type the values are, as they are just selected at random out an array. However, the return type is linked to the the input type. The params are first and return value last. The following is inspired by C# generics.
_fnc_map_selectRandom = {
selectRandom _this; // Does not care what type the values are
}
If we wanted to accept a matching param and return signature, it could be expressed as:
<CODE<Map<T>,KeyPair<T>> A select random weighted function that takes any value type.
Sometimes multiple generic types may be required:
_fnc_swap = {
param ["_var1","_var2"];
[_var2,_var1];
}
If we wanted to accept a matching param and return signature, it could be expressed as:
<CODE<T1,T2,<T2,T1>> A select random weighted function that takes any value type.