ObjectType == objectType
by Dan Pascal · in Torque X 2D · 01/01/2009 (10:37 am) · 6 replies
How can you compare objectTypes in code?
I'd like to do this
if (objectTypeA == objectTypeB) { }
but that's a no go.
Happy new year all, by the way,
I'd like to do this
if (objectTypeA == objectTypeB) { }
but that's a no go.
Happy new year all, by the way,
About the author
#3
Just for some clarification for others, the TestObjectType() method is located in the GarageGames.Torque.Code.TorqueObject class (GarageGames.TorqueX.Framework.dll).
Also, I had some issues when trying to find the ObjectType of a T2DTileObject since T2DTileObject doesn't inherit from TorqueObject and the TestObjectType() method isn't static yet the T2DTileObject class contains an ObjectType.
Anyways, if you need to test if an ObjectType exists with two ObjectTypes you can simply use the binary and operator (&) that is overloaded on the TorqueObjectType structure.
For example, say you have an ObjectType of "Test" that is registered with the TorqueObjectDatabase already and you want to test if this is set on an object:
//If ObjectToTest contains TorqueObjectType of "Test"
if(ObjectToTest.ObjectType & TorqueObjectDataBase.Instance.GetObjectType("Test"))
{
}
Hope that helps anyone that had the same issue as I did. If anyone knows of an easier way to do this, please let me know; this was the only solution I was able to find.
01/04/2009 (8:16 pm)
Thanks Viktor, this post has helped me with this issue also.Just for some clarification for others, the TestObjectType() method is located in the GarageGames.Torque.Code.TorqueObject class (GarageGames.TorqueX.Framework.dll).
Also, I had some issues when trying to find the ObjectType of a T2DTileObject since T2DTileObject doesn't inherit from TorqueObject and the TestObjectType() method isn't static yet the T2DTileObject class contains an ObjectType.
Anyways, if you need to test if an ObjectType exists with two ObjectTypes you can simply use the binary and operator (&) that is overloaded on the TorqueObjectType structure.
For example, say you have an ObjectType of "Test" that is registered with the TorqueObjectDatabase already and you want to test if this is set on an object:
//If ObjectToTest contains TorqueObjectType of "Test"
if(ObjectToTest.ObjectType & TorqueObjectDataBase.Instance.GetObjectType("Test"))
{
}
Hope that helps anyone that had the same issue as I did. If anyone knows of an easier way to do this, please let me know; this was the only solution I was able to find.
#4
//If ObjectToTest contains TorqueObjectType of "Test"
if(ObjectToTest.ObjectType & TorqueObjectDatabase.Instance.GetObjectType("Test"))
{
}
01/22/2010 (3:20 am)
Correction://If ObjectToTest contains TorqueObjectType of "Test"
if(ObjectToTest.ObjectType & TorqueObjectDatabase.Instance.GetObjectType("Test"))
{
}
#5
11/16/2010 (4:34 pm)
Does this work for tiles as well? In the following code, my ObjectType always comes up empty:T2DTileObject tileHit = Tilemap.PickTile(projectLine);
if (tileHit != null)
{
if (tileHit.ObjectType & TorqueObjectDatabase.Instance.GetObjectType("DenTile"))
{
int xGridCoord = (int)tileHit.GridPosition.X;
int yGridCoord = (int)tileHit.GridPosition.Y;
//Delete the hit tile map
Tilemap.SetTileByGridCoords(xGridCoord, yGridCoord, emptyTile);
}
}
#6
//If ObjectToTest contains TorqueObjectType of "Test"
if(ObjectToTest.TileType.ObjectType & TorqueObjectDatabase.Instance.GetObjectType("Test"))
{
}
11/16/2010 (5:19 pm)
Figured it out. Had to refer to to the TileType class first://If ObjectToTest contains TorqueObjectType of "Test"
if(ObjectToTest.TileType.ObjectType & TorqueObjectDatabase.Instance.GetObjectType("Test"))
{
}
Torque Owner Viktor Rumanuk