# Scope of Variables

By default, variable and function names are recognized globally (as in the BASIC language). Once a name is mentioned in a valid FISH statement, it is thereafter recognized globally, both in FISH code and in FLAC3D commands (for example, using inline FISH in place of a number). A variable also appears in the list of variables displayed when the fish list symbols command is given, and in the user interface in the FISH Global Symbols control set.

If the local identifier is used to declare a variable, the variable is considered local to that function and is not available once the function has been executed. Local variables supersede global variables in a function.

If the FISH variable automatic creation option is disabled (see the fish automatic-create command), all global variables must be declared with the global keyword. A global variable may be given a value in one FISH function, and used in another function or in a FLAC3D command. The value is retained until it is changed. The values of all global variables are also saved by the model save command and restored by the model restore command.

We strongly recommend that once the user has become comfortable with FISH, and has begin writing functions of even moderate complexity, they set fish automatic-create to off for all data files. Accidentally creating a new global FISH symbol (with a default value of 0) by mistyping a variable name can be the cause subtle and difficult to find bugs.

The following is a brief example of declaring global symbols and local variables in FISH:

fish define test
;; Declare two global symbols
global aa = 0, bb = 'a'
;; Declare two local variables
local cc = 3, dd = 'test'
end
[test]
fish define test
!    test = aa + bc ; This is an error, bc has not been declared