Identifier: Difference between revisions
Jump to navigation
Jump to search
(fixed: floating table was floating too far) |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
An [[Identifier]] is the name given to a [[Variables|variable]] that the scripter can choose: It is the name that ''identifies'' the variable. | An [[Identifier]] is the name given to a [[Variables|variable]] that the scripter can choose: It is the name that ''identifies'' the variable. | ||
== Rules == | == Rules == | ||
{| class="wikitable" | {| class="wikitable float-right" | ||
! Valid | |+ Regex: {{hl|[a-zA-Z_][a-zA-Z0-9_]*}} | ||
! Valid | |||
! Invalid | |||
|- | |- | ||
| | | | ||
Line 24: | Line 25: | ||
* Identifiers are '''case-insensitive'''. | * Identifiers are '''case-insensitive'''. | ||
* Identifiers '''cannot be the same as reserved words''' (e.g [[:Category:Scripting Commands|commands]] and [[:Category:Functions|functions]]). | * Identifiers '''cannot be the same as reserved words''' (e.g [[:Category:Scripting Commands|commands]] and [[:Category:Functions|functions]]). | ||
== Recommendations == | == Recommendations == | ||
It is recommended to write '''local variable identifiers''' in {{Wikipedia| | |||
< | It is recommended to write '''local variable identifiers''' in {{Wikipedia|Camel case|camel case}} syntax. This makes identifiers more readable: | ||
<sqf>private _myVariableName = 5;</sqf> | |||
{{Feature|important| | |||
{{Wikipedia|Snake case}} is sometimes encountered but is not recommended and should be avoided: | |||
<sqf>_my_variable_name = 5;</sqf> | |||
}} | |||
It is also recommended to prefix '''global variable identifiers''' with '''your''' [[OFPEC tags|tag]] in order to avoid any potential conflict between addons, scripts and missions: | It is also recommended to prefix '''global variable identifiers''' with '''your''' [[OFPEC tags|tag]] in order to avoid any potential conflict between addons, scripts and missions: | ||
{{cc|'''{{Color|purple|Tag}}'''_identifier}} | |||
<span style="color: purple; font-weight: bold">UNIQUETAG</span>_player = [[player]]; | <span style="color: purple; font-weight: bold">UNIQUETAG</span>_player = [[player]]; | ||
== See also == | == See also == | ||
* [[Variables]] | * [[Variables]] | ||
[[Category: Syntax]] | [[Category: Syntax]] |
Revision as of 16:46, 10 January 2023
An Identifier is the name given to a variable that the scripter can choose: It is the name that identifies the variable.
Rules
Valid | Invalid |
---|---|
|
|
Binding rules for identifiers:
- Identifiers may consist of any ASCII text characters (a-z, A-Z), numbers (0-9) and underscores (_).
- Identifiers must not start with a number (e.g "9myVariable" is invalid).
- Identifiers of local variables must start with an underscore.
- Identifiers are case-insensitive.
- Identifiers cannot be the same as reserved words (e.g commands and functions).
Recommendations
It is recommended to write local variable identifiers in camel case syntax. This makes identifiers more readable:
It is also recommended to prefix global variable identifiers with your tag in order to avoid any potential conflict between addons, scripts and missions:
// Tag_identifier UNIQUETAG_player = player;