Identifier: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Fix wording) |
(fixed: floating table was floating too far) |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | |||
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" | ||
! Valid !! Invalid | ! Valid !! Invalid | ||
|- | |- | ||
Line 12: | Line 13: | ||
* _player | * _player | ||
| | | | ||
* | * {{Color|red|1}}variable | ||
* _my | * _my{{Color|red|#}}localVar | ||
* _guy1 | * _guy1{{Color|red|&}}2var | ||
* | * {{Color|red|player}} | ||
|} | |} | ||
Binding rules for identifiers: | Binding rules for identifiers: | ||
* Identifiers may consist of any ASCII text characters (a-z, A-Z), numbers (0-9) and underscores (_) | * 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 | * Identifiers '''must not''' start with a number (e.g "9myVariable" is invalid). | ||
* Identifiers of | * Identifiers of [[Variables|local variables]] '''must''' start with an underscore. | ||
* Identifiers are '''case-insensitive'''. | * Identifiers are '''case-insensitive'''. | ||
* Identifiers '''cannot be the same as reserved words''' (e.g [[ | * 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|Camel_case|camel case}} syntax. This makes identifiers more readable: | |||
It is recommended to write ''' | |||
<code>[[private]] _myVariableName = 5;</code> | <code>[[private]] _myVariableName = 5;</code> | ||
It is also recommended to prefix ''' | 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: | ||
<code>{{cc|<span style{{=}}"color: purple; font-weight: bold">Tag</span>_identifier}} | <code>{{cc|<span style{{=}}"color: purple; font-weight: bold">Tag</span>_identifier}} | ||
<span style="color: purple; font-weight: bold">UNIQUETAG</span>_player = [[player]];</code> | <span style="color: purple; font-weight: bold">UNIQUETAG</span>_player = [[player]];</code> | ||
Line 36: | Line 35: | ||
A less encountered naming format is separating all sub-words with underscores: | A less encountered naming format is separating all sub-words with underscores: | ||
<code>_my_variable_name = 5;</code> | <code>_my_variable_name = 5;</code> | ||
== See also == | == See also == | ||
* [[Variables]] | * [[Variables]] | ||
[[Category: Syntax]] | [[Category: Syntax]] |
Revision as of 16:51, 30 December 2020
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:
private _myVariableName = 5;
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;
A less encountered naming format is separating all sub-words with underscores:
_my_variable_name = 5;