Identifier: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (private → local, public → global) |
Lou Montana (talk | contribs) m (Fix typo) |
||
Line 19: | Line 19: | ||
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 [[All Arma Commands Pages|commands]] and [[:Category:Functions|functions]]). | * Identifiers '''cannot be the same as reserved words''' (e.g [[All Arma Commands Pages|commands]] and [[:Category:Functions|functions]]). |
Revision as of 21:29, 15 November 2020
An identifier is a 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;