Recently I was asked how to use global variables inside global functions using VSL, one of 3DVIA Virtools built-in scripting languages.
In VSL you can share a variable across diferent "Run VSL" BuildingBlocks by using the keyword "shared". For example
Besides using VSL in BBs or actionscripts, you can also create "global" VSL scripts. These are automatically included. The things is that you can not use the shared keyword inside global scripts. So if you want to modify shared variables inside global functions, one workaround is to use parameter-objects.
Basically it's a struct containing variables you like to share. Either one struct for all or split your variables by context into different structs. This user defined structure makes passing them to functions much easier. Also less code changes are required when adding more data.
Above you see the definition and how it's used as input parameter of a global function. This works because it's passed by reference and not as value (/copy). This way you can modify shared variables even inside global functions. Here is how it could look like inside a VSL BB that calls the global function:
I hope this will help a few more people. If it's not clear, let me know.










