Aside from its arguments, a defined command has no access to any variables outside of it. So the following would trigger an error:
$outer = 9
Define Command DoSpecial($arg)
Return $outer + $arg # error, $outer is hidden from our command
End
$result = DoSpecial(11)
You can however declare that an external variable be made visible to the command using the Import Var command:
$outer = 9
Define Command DoSpecial($arg)
Import Var 'outer' # we can now use $outer in our command
Return $outer + $arg
End
$result = DoSpecial(11)
When you import a variable this way, the command has read and write access to the variable, and any changes to the variable are visible to the enclosing scope:
$count = 0
Define Command IncrementCount
Import Var 'count'
$count += 1 # modify the outer $count variable
End
IncrementCount
IncrementCount
Prompt $count # will show 2
Previous Chapter Arguments |
<< index >> |
Next Chapter List Argument |