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 Define and Protected are read as LOCAL.
  • LOCAL belongs inside a FUNCTION. At the top of the program, a LOCAL (or Define) variable assigned again later makes a program that does not start (Identifier … has already been declared). Use GLOBAL or AS there.
  • Inside a FUNCTION, a name that is neither a parameter, nor LOCAL, nor GLOBAL, nor assigned by the program above the function, is a new local variable anyway. LOCAL makes the intent clear and is required to hide a program variable.
  • Under OPTION EXPLICIT, LOCAL counts 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 1
In the manual : Variables and types