Hi Matthew,
I understand that you want to understand the scope of variables you are using for your subsystem which are defined in the initialization function of the models. Further, you want to know if there is any way to define variables that have scope to the subsystem or model.
Yes, the understanding of the base workspace variable behaviour is correct. When multiple subsystems are initialized, each one may set the base workspace variables during its initialization. The final state of these variables will reflect the last subsystem that was initialized.
However, using base workspace variables in this way can lead to confusion and is generally not recommended because it's hard to track the changes and the scope is global, which could lead to unexpected behaviour.
To have duplicate variables scoped to each subsystem, Masks or the Data Store Memory blocks can be used.
Here's an example of how to use and create Mask for the above stated purpose:
- Right click on your subsystem.
- Select Masks and then Create Mask.
- In the Parameters & Dialog tab, you can add “Edit” parameter for all the local variables.
- Now you can make copies of this masked subsystem and double click on it to set the values of the variables.
You can refer to the following documentation pages for more insight on “Masks” and the “Data Store Memory Block”:
Hope this helps and resolves your issue.
Thanks
Gyan