Having Trouble Accesing a Component from a List
by George_Gamer · in Torque X 2D · 03/26/2009 (6:56 am) · 2 replies
Ok, so I am making a platform game and am trying to make it so that when I press a button everything around may character will "activate" or use is UseAction function. Here is my search code:
public virtual void Action1(bool active)
{
if (active)
{
foundObjects.Clear();
T2DSceneGraph sceneGraph = TorqueObjectDatabase.Instance.FindObject<T2DSceneGraph>("DefaultSceneGraph");
TorqueObjectType unitType = TorqueObjectDatabase.Instance.GetObjectType("useable");
sceneGraph.FindObjects(SceneObject.Position, 2.0f, unitType, 0xFFFFFFFF, foundObjects);
}
foreach (ISceneContainerObject obj in foundObjects)
{
UseableComponent UseComp = ((T2DSceneObject)obj).Components.FindComponents<UseableComponent>();
UseComp.UseAction(active);
}
}
I keep getting this error:
Cannot implicitly convert type 'System.Collections.Generic.List<PlatformerStarter.UseableComponent>' to 'PlatformerStarter.UseableComponent'
I am still learning TorqueX, but I think its a Casting error but I cant figure it out. If anyone can help me fiqure this out or give me another suggustion on how to do this I would really appreciate it. :)
public virtual void Action1(bool active)
{
if (active)
{
foundObjects.Clear();
T2DSceneGraph sceneGraph = TorqueObjectDatabase.Instance.FindObject<T2DSceneGraph>("DefaultSceneGraph");
TorqueObjectType unitType = TorqueObjectDatabase.Instance.GetObjectType("useable");
sceneGraph.FindObjects(SceneObject.Position, 2.0f, unitType, 0xFFFFFFFF, foundObjects);
}
foreach (ISceneContainerObject obj in foundObjects)
{
UseableComponent UseComp = ((T2DSceneObject)obj).Components.FindComponents<UseableComponent>();
UseComp.UseAction(active);
}
}
I keep getting this error:
Cannot implicitly convert type 'System.Collections.Generic.List<PlatformerStarter.UseableComponent>' to 'PlatformerStarter.UseableComponent'
I am still learning TorqueX, but I think its a Casting error but I cant figure it out. If anyone can help me fiqure this out or give me another suggustion on how to do this I would really appreciate it. :)
#2
03/26/2009 (10:36 am)
LOL, Thank you, it was FindComponent not FindComponents. I quess I should have read all the function names before using the auto compelete in Visual Studios. Well the code works now and Thanx agian.
Torque Owner Talcott Langston