Game Development Community

Calling onCollision without Datablock Tag

by Jamie Zephyr · in Torque Game Engine · 04/30/2008 (12:35 pm) · 4 replies

When you run DATABLOCK::onCollision it is based on the datablock of the object. What I am doing is taking an object and replacing it with a new model (destroyed state in the game). To do this I must create new datablock (datablock = destroyedObject) meaning the old DATABLOCK::onCollision will not be called anymore.

What I was wondering is if there is a way to tag all objects that can be collided with (all destructible objects in game) so that way I can call the onCollision method like this:

TAGGEDNAME::onCollision
{
//run this code
}

#1
04/30/2008 (1:49 pm)
If I understand your question correctly .. try using 'classname' in your datablock to insert a function namespace.


classname = "TAGGEDNAME"; // edit - added quotes

Then your datablock will use the functions of the TAGGEDNAME datablock.
#2
04/30/2008 (4:53 pm)
Awesome that seems to work. Just so I am understanding this fully, if I set a (I think its called) a tagged field (which I think I understand) must be of classname = "TAGGEDNAME" I can use functions on every object with that classname?

I apologize if my terminology is off, I am fairly new to torque/game programming but I really want to learn! Thanks mb!
#3
05/02/2008 (7:56 am)
I wouldn't called that a "tagged field" as people might confuse that with a "tagged string" which is a string enclosed in single quotes ('example'). However, your functionality is correct. Whatever name you give in the className field becomes an additional "namespace" for that object which exists between the namespace of the object name and its "true" class. So, for example, let's say you have this object:
datablock PlayerData(SomeGuy) {
   className = "ThoseGuys";
};
You can have a function that is scoped specifically to that datablock by scoping it to the object name:
function SomeGuy::foo()
You can have a function scoped to the objects "className" which will be called for any datablocks with the same className:
function ThoseGuys::foo()
Finally, you can scope a function so that all objects of the same type run that functionality:
function PlayerData::foo()

So those are some options you have for different ways to scope your functions and functionality. I believe the overriding rule in the "computer science" world is to define your functions with as "tight" as scope as possible.
#4
05/05/2008 (6:21 am)
Great thanks!