Loosely related to: Polyscope X: Function Arguments - Product Wishlist - Universal Robots Forum
Summary
Add configurable variable scopes (Private, Module, Global) in PolyScope X
What is it?
Today, every variable created through PolyScope X assignment nodes is effectively global, regardless of where it is defined.
This applies to variables created in:
- Main Program
- Before Start Sequence
- Functions
- Functions running as threads
There is currently no mechanism to define the visibility or scope of a variable.
Requested enhancement:
When creating or assigning a variable, extend the configuration from:
Variable | Value Type | Expression
to:
Visibility | Variable | Value Type | Expression
Suggested scope options:
- Private – visible only inside the current function or thread
- Module – visible only within the current module
- Global – visible throughout the entire program
Example UI concept:
Suggested default behaviour:
| Location | Default Scope |
|---|---|
| Main Program | Global |
| Before Start | Global |
| Within Module (Thread/Function) | Private |
Users could still explicitly change the scope when needed.
Why is it needed?
The current global-only behaviour creates several challenges during development.
All variables share the same namespace, regardless of where they are created. This leads to:
- Increased risk of name collisions
- Accidental overwriting of variables
- Difficult-to-diagnose bugs
- Reduced modularity
- Less reusable program components
- Poorer readability in larger projects
As projects grow, developers must manually establish naming conventions to avoid conflicts. While naming conventions help, they are only a workaround for a missing language feature.
Scoped variables are a standard concept in modern programming environments because they provide:
- Better encapsulation
- Improved code organisation
- Greater program robustness
- Reduced risk of unintended side effects
- Easier maintenance and debugging
- Clear ownership of variables
Introducing variable scopes would allow developers to keep implementation details local to a function or module while exposing only the data that must be shared.
This would significantly improve the development experience in PolyScope X, especially for larger and more modular applications, while making programs easier to understand and maintain over their entire lifecycle.
As URScript already knows “non-global” variables, the proposed solution requires only a minimal UI change while providing substantial benefits for software quality, maintainability and scalability. It also aligns PolyScope X with common programming practices that developers already expect from modern development environments.
