constant

declares one or more constants and assigns values to them.

# Metadata

Platforms: desktop, server, mobile OS: mac, windows, linux, ios, android Introduced: 1.0 Changed:10.0 Security:

# Syntax

constant constantName [= value] [, constantName [= value] ...]

# Params

- constantName : The constantName is any identifier. - value : The <value> is any constant expression.

# Examples

constant kDefaultName = "Jones"

constant kEntryA = "EF9993333WX786", kEntryB = "GJ773281YX342"

constant kPiBy2 = pi / 2

constant kFoo = "foo" constant kBar = "bar" constant kFooBar = kFoo & kBar

constant kMap = { "a": 1, "b": 1 + 2 }

# Description

Use the constant command to assign an unchanging value to a keyword.

A constant's value can be anything, including arrays, as long as it can be defined by an expression which can be computed when the script is compiled. The majority of operators and functions can be used, as long as their operands and arguments are literals or other (previously defined) constants.

>*Note:* If the expression uses functions or operators which use local property, then the properties will be taken to be the default values, regardless of where the constant is defined.

>*Note:* Choose easy-to-understand names for > constants to improve the readability of your > code. Use constants as substitutes for long or > convoluted strings. Use the prefix letter k for your constant > names to follow convention and make it easy to recognise. See the > Tips For Writing Good Code in the Livecode Script Guide.

If you place the constant statement in a handler, you can use the constant anywhere in the handler. If you place the constant statement in a script outside any handler, you can use the constant anywhere in the handlers of that script.

Once you have defined a constant, you cannot redefine it in the same handler; doing so causes an execution error.

You can use the constant command to redefine LiveCode built-in constants within a script or handler, but doing so makes your code harder to read and maintain. To find out whether a word is already defined as a built-in constant, use the constantNames function.

>*Tip:* To see a list of built-in constants, open the Documentation > window, click LiveCode Dictionary, and choose "Constants" from the > menu at the top of the window.

# Tags

# See

- **property:** script - **constant:** watch, false, slash, comma, plus, null, pi, iBeam, colon, three, formfeed, help, five, zero, seven, eight, CRLF, quote, empty, space, arrow, six, ten, four, two - **command:** constant, local - **function:** constantNames - **control structure:** function - **glossary:** LiveCode, value, handler, string, statement, constant, keyword, command, declare, local property