Game Development Community

1.5 Strategy Master Tutorial Problem

by Chip Lambert · in Torque X 2D · 01/20/2008 (4:51 pm) · 8 replies

Hey guys I'm doing the strategy master tutorial in 1.5 and I put this block of code in as it said in the tutorial:

protected T2DSceneObject _GetUnit(Vector2 location, TorqueObjectType unitType)
  {
      List<ISceneContainerObject> foundObjects = new List<ISceneContainerObject>();
      T2DSceneGraph.Instance.FindObjects(location, 1.0f, unitType, 0xFFFFFFFF, foundObjects);

      if (foundObjects.Count == 1)
          return foundObjects[0] as T2DSceneObject;
      else
          return null;
  }

Few steps later I go to compile, and I get this error:

'GarageGames.Torque.T2D.T2DSceneGraph' does not contain a definition for 'Instance'

Did I miss a step? I went back over and made sure, but I could still be doing something wrong. Thanks!

#1
01/20/2008 (5:10 pm)
No, you're not doing anything wrong. We didn't update the tutorials to match all of the changes in 1.5 for the beta, and this is one of those places. In Torque X 1.5, you can have multiple scenegraphs, so it doesn't make sense to have an "instance" property, like it did when there could only ever be one scenegraph. You can get access to the scenegraph an object is in from a property of the object now.
#2
01/20/2008 (5:23 pm)
Thanks for the reply Dan. What would I need to change this line to:

T2DSceneGraph.Instance.FindObjects(location, 1.0f, unitType, 0xFFFFFFFF, foundObjects);

I haven't gotten a chance to really get into the framework and all, so I'm still skirting on the basics with TorqueX :)
#3
01/20/2008 (5:34 pm)
Try:
SceneObject.SceneGraph.FindObjects(location, 1.0f, unitType, 0xFFFFFFFF, foundObjects);
#4
01/20/2008 (5:36 pm)
That generated this error:

'GarageGames.Torque.SceneGraph.BaseSceneGraph' does not contain a definition for 'FindObjects'
#5
01/20/2008 (5:54 pm)
OK, try:
((T2DSceneGraph)SceneObject.SceneGraph).FindObjects(location, 1.0f, unitType, 0xFFFFFFFF, foundObjects);
#6
01/20/2008 (5:58 pm)
Thanks Dan! That worked. Wow I would have never figured that one out. Don't mind me asking and you have the time to explain, why does adding the paranthesis work? I've been using C# for a few months now at work (web and desktop app) but I haven't came across that yet.
#7
01/20/2008 (7:06 pm)
I'll try.
(SomeType)Name
casts the variable Name as type SomeType. So
(T2DSceneGraph)SceneObject.SceneGraph
is casting the SceneGraph property as a T2DSceneGraph type (the property is defined as a BaseSceneGraph type, which T2DSceneGraph is derived from). The next set of parenthesis are just to make sure that the FindObjects call is on the T2DSceneGraph interpretation of SceneObject.SceneGraph (since otherwise the compiler would probably try to apply the "cast" operator onto the return value of the FindObjects call, but that wouldn't work because FindObjects is a method of T2DSceneGraph, not BaseSceneGraph. Basically, what the code is doing is essentially this:
T2DSceneGraph tmp = SceneObject.SceneGraph as T2DSceneGraph;
tmp.FindObjects(location, 1.0f, unitType, 0xFFFFFFFF, foundObjects);
Does that make sense?
#8
01/20/2008 (7:08 pm)
I understand it completely. Thanks for help Dan.