ValueInterface Interface: namefield not recognized
by Arden · in Torque X 2D · 09/10/2010 (2:34 pm) · 5 replies
Hiya all,
I'm trying to share a string type field between two components. In the host one, I first declare the local field as an interface type:
Then, once it is declared, I register it for other components to find:
Finally, in the client component, I input the following reference private field:
So far so good. Then, as a final step, I connect the local field with the other component:
My problem at this stage is that Humanoid_heading is not recognized as a valid shared field, so I cannot compile.
You guys have a suggestion on what I might be missing?
Thanks
I'm trying to share a string type field between two components. In the host one, I first declare the local field as an interface type:
ValueInPlaceInterface<string> _Humanoid_heading = new ValueInPlaceInterface <string>("");Then, once it is declared, I register it for other components to find:
protected override void _RegisterInterfaces(TorqueObject owner)
{
base._RegisterInterfaces(owner);
Owner.RegisterCachedInterface("string","Humanoid_heading",this,_Humanoid_heading);
}Finally, in the client component, I input the following reference private field:
ValueInPlaceInterface <string> _Humanoid_heading;
So far so good. Then, as a final step, I connect the local field with the other component:
if (!base._OnRegister(owner) || !(owner is T2DSceneObject))
return false;
_sceneObject = owner as T2DSceneObject;
Humanoid_heading = Owner.Components.GetInterface<ValueInterface<string>>("string", "Humanoid_heading");My problem at this stage is that Humanoid_heading is not recognized as a valid shared field, so I cannot compile.
You guys have a suggestion on what I might be missing?
Thanks
#2
Any idea why?
09/10/2010 (4:28 pm)
I do have one question though. When testing out the string from the client Component, I'm getting a NullReference exception on the condition.if (_Humanoid_heading.Value == "W")
{
_sceneObject.FlipX = true;
}Any idea why?
#3
10/24/2010 (9:37 pm)
Im having the same problem with the NullReference exception. Does anyone know how to fix this?
#4
if(Humanoid_heading != null && Humanoid_heading.Value == "W" && _sceneObject != null) _sceneObject.FlipX = true;
To prevent the Null Ref occurring is something was not yet intialized when this check runs.
Hope it helps,
10/27/2010 (2:09 am)
so is the problem at run time the line evaluating to null.value or after the condition null.FlipX? In either event just add a null check to yout conditions something likeif(Humanoid_heading != null && Humanoid_heading.Value == "W" && _sceneObject != null) _sceneObject.FlipX = true;
To prevent the Null Ref occurring is something was not yet intialized when this check runs.
Hope it helps,
#5
10/28/2010 (3:14 pm)
Thanks for the advice Jon.
Torque Owner Arden