Game Development Community

Setting T2dObjectType With a String

by Rich Wilson · in Torque X 2D · 10/16/2007 (9:12 pm) · 3 replies

I'm trying to make a bomb object. When it goes off, it uses the FindObjects method to look for nearby objects of the 'bombable' Object Type. I could set this as a T2dObjectType public parameter that I can set in the tool, but it's always going to be 'bombable', so I'd like to hard code this inside the object instead of leaving it exposed.

So far I'm not finding a very clear-cut way to do this. When I use AllObjects for the filter in FindObjects, and try to see what the ObjectType.Name is for each object returned, I get "unknown" as the string, even though the objects are set to the "bombable" type in TXB.

I'm probably missing something here.

#1
10/17/2007 (1:25 pm)
This is just a limitation in the way the engine handles object types. Internally, an object type is just a bit mask, so after it's set, the engine doesn't know what string it was set with. This could be fixed by storing a dictionary of bits to names and then doing a reverse lookup, but that doesn't really help because objects usually have multiple object types.

You can however look up the object type bit by the string via TorqueObjectDatabase.Instance.GetObjectType("objectType"). So your code would end up looking something like this object.TestObjectType(TorqueObjectDatabase.Instance.GetObjectType("bombable")); That will return true if object is of type bombable.
#2
10/17/2007 (8:13 pm)
Not sure if this helps. I use the following code to pull up a list of game objects within a variable area relative to my player. In Torque X Builder, I have created an object type called "AI" and I applied that object type to several game objects within the scene.

public void FindNearbyAI( float distance )
{
    //get the current position of the player
    _playerPosition = _player.Position;
 
    //fill a list of all enemies
    _listEnemies = new List<ISceneContainerObject>();
 
    TorqueObjectType typeEnemy = TorqueObjectDatabase.Instance.GetObjectType("AI");
 
    T2DSceneGraph.Instance.FindObjects(_playerPosition, distance, typeEnemy, 
        (uint)0xFFFFFFFF, _listEnemies);
}

This seems to be working fine for me.

John K.
#3
10/28/2007 (7:42 am)
Thanks guys. GetObjectType worked like a charm. Not sure how I missed that.