Technical data

2
Working with the Target Language
2-38
Within the scope of a function, variable assignments always create new local
variables unless you use the
:: scope resolution operator. For example, given
a local variable
foo and a global variable foo:
%function
%assign foo = 3
%endfunction
In this example, the assignment always creates a variable foo local to the
function that will disappear when the function exits. Note that
foo is created
even if a global
foo already exists.
In order to create or change values in the global scope, you must use the
::
operator to disambiguate, as in:
%function
%assign foo = 3
%assign ::foo = foo
%endfunction
The :: forces the compiler to assign to the global foo, or to change its existing
value to 3.
Note: It is an error to change a value from the RTW file without qualifying it
with the scope. This example does not generate an error:
%assign CompiledModel.name = "newname" %% No error
This example generates an error:
%with CompiledModel
%assign name = "newname" %% Error
%endwith