Strategy Master Tutorial Problem
by Jim Drury · in Torque X 2D · 10/12/2008 (9:14 am) · 8 replies
I am going through and doing the tutorials for Torque X, and have run into a wall while doing the "Futuristic Strategy Master" tutorial. After I finished programming Step 4 of the tutorial it would not longer Run or Build and displayed the following error:
The line of code in question is:
When I try to type in that line auto-complete does not have all the items that it should. After typing "T2DSceneGraph." it just lists 'Equals', 'ReferenceEquals', and 'TorqueObjectFlags', and does NOT list 'Instance' or an of the other options.

The strange thing is that C# recognizes it as a key-word. I can even right-click on it and "Go To Definition" and it comes up with one that looks correct to me.

I've tried to see what comes up on the auto-complete in other projects that I have done and it acts exactly the same way, so I know the issue is not project specific. I've also tried to uninstall/reinstall Torque X 2.0 in case there was some sort of issue with my install, that did not help either. If anyone has any suggestions I would greatly appreciate it. I posted this else where, but this seemed a more appropriate location for the question.
Thank you.
edit: fixed tags.
Quote:'GarageGames.Torque.T2D.T2DSceneGraph' does not contain a definition for 'Instance'
The line of code in question is:
T2DSceneGraph.Instance.FindObjects(location, 1.0f, unitType, 0xFFFFFFFF, foundObjects);
When I try to type in that line auto-complete does not have all the items that it should. After typing "T2DSceneGraph." it just lists 'Equals', 'ReferenceEquals', and 'TorqueObjectFlags', and does NOT list 'Instance' or an of the other options.

The strange thing is that C# recognizes it as a key-word. I can even right-click on it and "Go To Definition" and it comes up with one that looks correct to me.

I've tried to see what comes up on the auto-complete in other projects that I have done and it acts exactly the same way, so I know the issue is not project specific. I've also tried to uninstall/reinstall Torque X 2.0 in case there was some sort of issue with my install, that did not help either. If anyone has any suggestions I would greatly appreciate it. I posted this else where, but this seemed a more appropriate location for the question.
Thank you.
edit: fixed tags.
#2
I noticed that the updated tutorials that you linked to had a different solution.
However when I try to run their solution that I get this error:
10/12/2008 (2:15 pm)
Thank you! That did the trick. I knew the solution would be something simple like that, but I wasn't able to quite figure it out because my programming skills and experience are intermediate at best. I noticed that the updated tutorials that you linked to had a different solution.
T2DSceneGraph sceneGraph = TorqueObjectDatabase.Instance.FindObject("DefaultSceneGraph");
sceneGraph.FindObjects(location, 1.0f, unitType, 0xFFFFFFFF, foundObjects);However when I try to run their solution that I get this error:
Quote:Cannot implicitly convert type 'GarageGames.Torque.Core.TorqueBase' to 'GarageGames.Torque.T2D.T2DSceneGraph'. An explicit conversion exists (are you missing a cast?)
#3
A little modification to the code from the Updated Tutorials seems to have done the trick.
10/12/2008 (2:54 pm)
So your version got the code to compile, but when I started moving forward with the tutorial it broke other things. I think it is because it created a new Scene Graph instead of pointing at the existing one.A little modification to the code from the Updated Tutorials seems to have done the trick.
T2DSceneGraph sceneGraph = (T2DSceneGraph)TorqueObjectDatabase.Instance.FindObject("DefaultSceneGraph");
sceneGraph.FindObjects(location, 1.0f, unitType, 0xFFFFFFFF, foundObjects);
#4
10/12/2008 (2:54 pm)
TryT2DSceneGraph sceneGraph = TorqueObjectDatabase.Instance.FindObject<T2DSceneGraph>("DefaultSceneGraph");
sceneGraph.FindObjects(location, 1.0f, unitType, 0xFFFFFFFF, foundObjects);
#5
A little modification to the code from the Updated Tutorials seems to have done the trick.
10/12/2008 (5:53 pm)
So your version got the code to compile, but when I started moving forward with the tutorial it broke other things. I think it is because it created a new Scene Graph instead of pointing at the existing one.A little modification to the code from the Updated Tutorials seems to have done the trick.
T2DSceneGraph sceneGraph = (T2DSceneGraph)TorqueObjectDatabase.Instance.FindObject("DefaultSceneGraph");
sceneGraph.FindObjects(location, 1.0f, unitType, 0xFFFFFFFF, foundObjects);
#6
Newb programmer question: What is the difference between the way you cast it and the way I cast it? Both ways work seem to work perfectly.
10/12/2008 (5:57 pm)
Thanks for the reply, I actually posted my reply before I read yours ... I didn't refresh the page until after I posted.Newb programmer question: What is the difference between the way you cast it and the way I cast it? Both ways work seem to work perfectly.
#7
TorqueObjectDatabase.Instance.FindObject("DefaultSceneGraph") and returns an object of type TorqueBase (or null).
You can cast this, as in your example, using (T2DSceneGraph). As long as there is an object name DefaultSceneGraph and it is actually of type T2DSceneGraph, then all is fine.
If some clown added an object, say a T2DStaticSprite, and named it DefaultSceneGraph, bad things may happen ...
Using TorqueObjectDatabase.Instance.FindObject("DefaultSceneGraph") will return null if there is no T2DSceneGraph object named DefaultSceneGraph even if there is a T2DStaticSprite with that name. So this is generally safer and preferred.
Edit: oh, and you should probably be checking if sceneGraph == null in case there is no DefaultSceneGraph defined. Otherwise, you'll get a null reference exeption at runtime which your users may not appreciate :-)
10/12/2008 (6:19 pm)
TorqueObjectDatabase.Instance.FindObject("DefaultSceneGraph") callsTorqueObjectDatabase.Instance.FindObject
You can cast this, as in your example, using (T2DSceneGraph). As long as there is an object name DefaultSceneGraph and it is actually of type T2DSceneGraph, then all is fine.
If some clown added an object, say a T2DStaticSprite, and named it DefaultSceneGraph, bad things may happen ...
Using TorqueObjectDatabase.Instance.FindObject
Edit: oh, and you should probably be checking if sceneGraph == null in case there is no DefaultSceneGraph defined. Otherwise, you'll get a null reference exeption at runtime which your users may not appreciate :-)
#8
10/12/2008 (9:37 pm)
Thanks for solving the OP problem everyone. I need to jump into the TX tutorials to fix some of the code samples. Your help and patience is much appreciated!
Torque Owner Viktor Rumanuk
Try this instead.
T2DSceneGraph sg = new T2DSceneGraph(); sg.FindObjects(location, 1.0f, unitType, 0xFFFFFFFF, foundObjects);Edit: Link to updated tutorials