Local <var1> [, <var2>, ...] [= <expr1> [, <expr2>, ...]] |
The Local
statement is used to tell Hollywood that the specified variable
should be local. Additionally, it can also initialize your variable.
Local myvar ; tell Hollywood that myvar will be local r = GetType(myvar) ; returns #NIL DebugPrint(myvar) ; prints zero <other code> myvar = 5 ; now myvar is created as a local variable! |
The code above simply tells Hollywood that myvar shall be local if a value
is assigned to it. The statement Local myvar
will not initialize the
variable. The variable will still be of type Nil, i.e. it does not even
exist. myvar
is created when you set it to a specific value. Normally,
if the initial value is different from 0, you will do the initialization
in the Local statement, e.g.
Local myvar = 5 ; create local variable |
You can create and initialize as many variables as you like. Just use a comma on each side of the equal sign for that. Example:
Local myvar, myvar2, myvar3 = 5, 4, 3 |
The code above creates three new local variables and assigns the value 5
to myvar
, 4 to myvar2
and 3 to myvar3
.
Please note that the Local
statement does not have to be placed at the
beginning of a function/block as it is the case with variable declarations
in other programming languages. You can place it wherever you want and
it is no bad programming style to use Local
in the middle of a function.
For example, this code is fine:
Block DebugPrint("Now calling TestFunc()") Local r = TestFunc() DebugPrint("Now calling TestFunc2()") Local r2 = TestFunc2() DebugPrint("Results:", r, r2) EndBlock |
This code uses Local
in the middle of a new block which is no problem with
Hollywood.
See Local variables for details.