Accessing a variable from another component
by Eric Sapp · in Torque X 2D · 02/26/2008 (9:20 pm) · 2 replies
Hey all,
I'm trying to have one component switch a variable to true or false on a different component. However, I keep getting an error message that says this variable is unavailable due to it's protection level when I use this code;
T2DSceneObject X = _OtherObject as T2DSceneObject;
OtherComponent objHand = X.Components.FindComponent();
if (X != null)
{
X._Variable = true;
}
Any help would be much appreciated, I know this is just a basic question on declaring public variables :)
Thanks.
-Eric
I'm trying to have one component switch a variable to true or false on a different component. However, I keep getting an error message that says this variable is unavailable due to it's protection level when I use this code;
T2DSceneObject X = _OtherObject as T2DSceneObject;
OtherComponent objHand = X.Components.FindComponent
if (X != null)
{
X._Variable = true;
}
Any help would be much appreciated, I know this is just a basic question on declaring public variables :)
Thanks.
-Eric
About the author
#2
Thanks for the help, you steered me down the right path. I didn't know you have to use public variables/ interface variables to talk between components and then pass that information to local variables to be used in each component.
03/01/2008 (5:55 pm)
Hey Scott, Thanks for the help, you steered me down the right path. I didn't know you have to use public variables/ interface variables to talk between components and then pass that information to local variables to be used in each component.
Torque Owner Scott Goodwin
public bool Variable { get { return _Variable; } }assuming it is a component you are writing. If it is an exisiting component, look for a public accessor for the variable.
Also, a completely different approach would be to use interface variables. Check out the tutorials for some excellent examples of using interface variables between components. That's probably what you really want anyway.