Forum Discussion
Hello Viji123,
I am new to TC as well, and not sure if below will help you.
I used Python for scripting as well. This is what I did based on your situation:
if you just declar the variable outside of function in Unit1, and import Unit1 to Unit2, then you can call the varaible.
Example:
Unit1 script looks like below:
var variable_from_unit1 = "Unit 1 variable"
Unit2 script looks like below:
import unit1
def get_unit1_variable():
Log.Message(Unit1.variable_from_unit1)
When you run the Unit2 script, you should get a messag "Unit 1 variable"
Hi shenyusun,
Thanks for the reply. I will try that out.
I would also like to know how i can call the variable which declared inside a function in Unit1 file from a Unit2 file
- shenyusun8 years agoContributor
I think when you declared a variable inside a function, the variable becomes private variable, and it can only be access within the function itself.
- tristaanogre8 years agoEsteemed Contributor
As shenyusun, it's a matter of scope... the variable in the function is scoped to only be accessible within the function.
If you were using JScript or JavaScript you could do something like this:function MyTest(){ this.MyVar = 'testing'; } function test1(){ TestVar = new MyTest(); Log.Message(TestVar.MyVar); }
What this basically does is turn the first function into an object declaration with a property called "MyVar". Again, I don't know Python very well so I don't know if this is possible. But this is how I would do it in a different language.
Related Content
Recent Discussions
- 57 minutes agoSubhraDas
- 15 hours agoJacobjacob44