Syntax
Declares a variable that belongs to one call of a FUNCTION. It hides a program variable of the same name.
LOCAL <name> [= <value>]
LOCAL <name> AS <type> [= <value>]
LOCAL <name>, <name>[, <name>…]
LOCAL NewList <name>.<type>()
LOCAL NewMap <name>.<type>()
Define <name> [= <value>]
Protected <name> [= <value>]Also written : Protected
Parts
| <name> | The variable's name. Without a value it starts at 0, or at "" for a $ name. |
|---|---|
| <value> | Optional starting value: any expression, computed at each call. |
| <type> | A number, string or record type for AS; the type of the elements for NewList and NewMap. |
Good to know
- PureBasic's
DefineandProtectedare read asLOCAL. LOCALbelongs inside a FUNCTION. At the top of the program, aLOCAL(orDefine) variable assigned again later makes a program that does not start (Identifier … has already been declared). UseGLOBALorASthere.- Inside a FUNCTION, a name that is neither a parameter, nor
LOCAL, norGLOBAL, nor assigned by the program above the function, is a new local variable anyway.LOCALmakes the intent clear and is required to hide a program variable. - Under
OPTION EXPLICIT,LOCALcounts as a declaration.
Example
score = 1FUNCTION Bump() LOCAL score = 99 LOCAL bonus AS integer = 2.5 Protected count count = count + 1 score = score + bonus + countENDFUNCTION scoreConsole(Str(Bump()) + " " + Str(score)) ' 102 1In the manual : Variables and types