Literals Reference

From the CreationKit Wiki
Revision as of 14:54, 13 January 2014 by imported>Egocarib
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Papyrus supports five kinds of literal values: boolean, integer, float, string, and None.

Boolean Literals

<boolean> ::= 'true' | 'false'
 bool myBoolean
 if myBoolean == true
    ;do something
 endif

Boolean literals are simple, they are just true or false values.

Integer Literals

<integer> ::= (['-'] <digit>+) | ('0x' (<digit>|<hex digit>)+)
 int count
 if count < 5
    ;do something
    count +=1
 endif

Integer literals are sequences of digits (0 though 9) optionally prefixed by a minus sign. If you want a hex number, prefix it with "0x". Valid hex digits are A through F (case-insensitive). Integers are 32-bits in size, signed, which means their valid range is −2,147,483,648 to 2,147,483,647.

Examples

10
-15365
0x0001F2C8

Float Literals

<float> ::= ['-'] <digit>+ '.' <digit>+
 float myValue
 if myValue ==  5.123
    ;do something
 endif


Float literals are sequences of digits (0 through 9) optionally prefixed by a minus sign, and followed by a dot and another sequence of digits. Floats are 32-bits in size, and have a range of 1.175494351 E – 38 to 3.402823466 E + 38 with 7 significant digits. They match the IEEE standard single type (23+1 significant bits and 8 exponent bits).

Examples

1.5234
-125412.0

String Literals

<string> ::= '"' <anything but another ", \, newline, or linefeed> '"'
 string myText = "Hello World."
debug.trace(myText)

String literals are simply text surrounded by double quotes. Newlines, line feeds, quotes, and back slashes are not allowed in the string. If you want one of these special characters, or a tab, then you can use the following escape codes:

\n Newline
\t Tab
\\ Backslash
\" Double quote

Examples

"Hello, World!"
"" ; Empty string
"\\\n" ; a string with a backslash followed by a new line

None Literal

None

The None literal simply represents 'nothing' for object types. (Similar to NULL in C) If you want to know if an object variable contains a valid object, just compare it to None.