Identifier: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
(Page refresh)
Line 1: Line 1:
An '''identifier''' is a name given to a [[Variables|variable]] that the scripter can choose: It is the name that ''identifies'' the variable.
An '''identifier''' is a name given to a [[Variables|variable]] that the scripter can choose: It is the name that ''identifies'' the variable.


== Rules ==
== Rules ==
 
{| class="bikitable" style="float: right; margin-left: 1em"
! Valid !! Invalid
|-
|
* variable1
* _my_local_variable
* _1variable
|
* <span style="color: red">1</span>variable
* _my<span style="color: red">#</span>localVar
* _guy1<span style="color: red">&amp;</span>2var
|}
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 (f.i. "9myVariable")
* Identifiers '''must not''' start with a number (e.g "9myVariable")
* Identifiers of [[Variables|local variables]] '''must''' start with an underscore
* Identifiers of [[Variables|local variables]] '''must''' start with an underscore


'''Examples of valid identifiers:'''
myVariable1
_localVariable95
_23Variable
'''Examples of invalid identifiers:'''
123Variable
9_vA#riable
_this&variable


== Recommendations ==
== Recommendations ==


It is recommended to write identifiers in camel-case-syntax. That means that all sub-words in the identifier are started with an upper-case character. This makes identifiers better readable.
It is recommended to write '''private variable identifiers''' in {{Wikipedia|Camel_case|camel case}} syntax. This makes identifiers more readable:
 
<code>[[private]] _myVariableName = 5;</code>
'''Example:'''
 
myCamelCaseIdentifier


Another but longer method is to split all sub-words with underscores.
It is also recommended to prefix '''public 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}}
<span style="color: purple; font-weight: bold">BIS</span>_player = [[player]];</code>


'''Example:'''
A less encountered naming format is separating all sub-words with underscores:
<code>_my_variable_name = 5;</code>


my_splitted_identifier


== See also ==
== See also ==


* [[Variables]]
* [[Variables]]


[[Category: Syntax]]
[[Category: Syntax]]

Revision as of 01:31, 4 November 2019

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
  • variable1
  • _my_local_variable
  • _1variable
  • 1variable
  • _my#localVar
  • _guy1&2var

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")
  • Identifiers of local variables must start with an underscore


Recommendations

It is recommended to write private variable identifiers in camel case syntax. This makes identifiers more readable: private _myVariableName = 5;

It is also recommended to prefix public variable identifiers with your tag in order to avoid any potential conflict between addons, scripts and missions: // Tag_identifier BIS_player = player;

A less encountered naming format is separating all sub-words with underscores: _my_variable_name = 5;


See also