Universal Robots Forum

Global variable already exists?

Is there a possibility in scriptcode to check if a global variable already exists?

Hello @chhoelzle , to my knowledge there isn’t anything in place to verify if a global variable already exist. I would recommend using unique names when creating your variables, for example ‘myCompany_force’ instead of force or something along those lines.

You could also try verifying by assigning a dummy variables to hold the value of the variable name in question. A program should stop and display an error if an unassigned variable is encountered. Hope that helps.

Thank you for your response. It’s not the problem, that I’d like to know if I’m using a new global variable, I’d like to check if I make a second instance of a program node. therefore I tried to set a global variable in the first instance and wanted to check if this already exists in the second instance.
So i have to find an other way.