I have a link with multiple sub-links, and I want to add an event handler to each of them. I’ve noticed some strange behavior: if I only include a print statement in my script, it is executed once. However, when I use a for loop, the loop is triggered twice. Is this a known behavior?
However, doing things in the global “module” scope of the script is generally problematic because that gets executed in quite varying situations / context such as:
When the script code changes and simulation is in reset state.
When script has been changed during simulation and then simulation is reset.
During layout loading, in an inner world of merge target world.
During component loading, apparently directly in the merge target world.
During special component loading like Product Type templates that never get attached to any world.
These matter mostly if the script accesses something outside the parent component, but that doesn’t seem to be your use case.
Seems you are using an external editor too. That could also affect things depending on how the script files get written to disk and VC reacting to the file system events produced by those changes.