Lexical structure

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (added UnityScript notice)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{UnityScript Notice}}
 +
 
== Scripts ==
 
== Scripts ==
  
Line 15: Line 17:
 
*byte
 
*byte
 
*case
 
*case
 +
*cast
 +
*catch
 
*char
 
*char
 
*class
 
*class
 
*continue
 
*continue
 
*default
 
*default
 +
*do
 
*double
 
*double
 +
*each
 
*else
 
*else
 
*enum
 
*enum
 +
*extends
 
*false
 
*false
 +
*final
 +
*finally
 
*float
 
*float
 
*for
 
*for
 +
*function
 +
*get
 
*if
 
*if
 +
*implements
 +
*import
 
*in
 
*in
 +
*instanceof
 
*int
 
*int
 +
*interface
 +
*internal
 
*long
 
*long
 
*new
 
*new
 +
*not
 
*null
 
*null
 +
*override
 +
*partial
 +
*<nowiki>#pragma</nowiki>
 +
*print
 
*private
 
*private
 
*protected
 
*protected
Line 36: Line 57:
 
*return
 
*return
 
*sbyte
 
*sbyte
 +
*set
 +
*short
 
*static
 
*static
 
*string
 
*string
Line 41: Line 64:
 
*switch
 
*switch
 
*this
 
*this
 +
*throw
 
*true
 
*true
 +
*try
 
*typeof
 
*typeof
 
*uint
 
*uint
 
*ulong
 
*ulong
 
*ushort
 
*ushort
 +
*var
 
*virtual
 
*virtual
 
*void
 
*void
 
*while
 
*while
 +
*yield
 +
 
=== Literals ===
 
=== Literals ===
 
:A literal is a source code representation of a value
 
:A literal is a source code representation of a value
Line 88: Line 116:
 
:: == != <= >= += -= *= /= %= &=
 
:: == != <= >= += -= *= /= %= &=
 
:: |= ^= <<= >>=
 
:: |= ^= <<= >>=
 +
 +
[[Category: JavaScript]]
 +
[[Category: Legacy]]

Latest revision as of 21:30, 21 November 2018

End of support for UnityScript

Starting with Unity 2018.2, support for UnityScript (Unity's version of JavaScript) has ended. C# is now the only supported language going forward. You can learn more about the reasons for this change here. There is an official UnityScript-to-C# Automatic Conversion tool to help those wanting to transition their UnityScript projects over to C#.


Contents

[edit] Scripts

Javascript for Unity is written inside of one or more script files. Each of these script files contains at least one class definition which must have the same name as the file, e.g. MyJavascript.js will contain the definition for the MyJavascript class. If no class is explicitly created, then Unity will automatically create a class with the correct name, and anything found inside of that file will be made a member of that class.

[edit] Tokens

[edit] Keywords

Keyword is an identifier-like sequence of characters that is reserved.

Keyword : one of

  • as
  • boolean
  • break
  • byte
  • case
  • cast
  • catch
  • char
  • class
  • continue
  • default
  • do
  • double
  • each
  • else
  • enum
  • extends
  • false
  • final
  • finally
  • float
  • for
  • function
  • get
  • if
  • implements
  • import
  • in
  • instanceof
  • int
  • interface
  • internal
  • long
  • new
  • not
  • null
  • override
  • partial
  • #pragma
  • print
  • private
  • protected
  • public
  • return
  • sbyte
  • set
  • short
  • static
  • string
  • super
  • switch
  • this
  • throw
  • true
  • try
  • typeof
  • uint
  • ulong
  • ushort
  • var
  • virtual
  • void
  • while
  • yield

[edit] Literals

A literal is a source code representation of a value

[edit] Boolean literals

There are two boolean literal values: true and false
The type of a boolean literal is boolean

[edit] Integer literals

Integer literals are used for values of type int, uint, long, and ulong
Integer literals can be of type decimal-integer-literal or hexadecimal-integer-literal
[edit] Decimal integer literal
Decimal integer literals are made of decimal-digits
[edit] Decimal digits
one of:
0 1 2 3 4 5 6 7 8 9
[edit] Hexadecimal integer literal
Hexadecimal integer literals are made of hexadecimal-digits
[edit] Hexadecimal digits
one of:
0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f

[edit] Real literals

Real literals are used to write values of float and double
Real literals can be written as:
decimal-digits . decimal-digits
. decimal-digits
decimal-digits
In real literals, a decimal point must be followed decimal digits. Therefore 1.0 is valid, but 1. is not

[edit] String literals

String literals consist of zero or more characters enclosed in double-quote characters.
A string literal is of type String

[edit] Null literal

The keyword null makes a null literal of type null

[edit] Operators and punctuators

Operators are used to describe operations between one or more operands. Punctuators are use for grouping and separating.
punctuators include:
{ } [ ] ( ) . , : ;
operators include
+ - * / % & | ^ ! ~
= < > ? ++ -- && || << >>
== != <= >= += -= *= /= %= &=
|= ^= <<= >>=
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox