Game Development Community

Datablocks and clone/cloneWithBehaviors

by WesTT · in Torque Game Builder · 02/22/2008 (12:56 am) · 4 replies

Hi all. I have a game I am developing that has multiple spawn points (t2dSceneObjects with attached spawn behaviors) and in these SP, I call cloneWithBehaviors on the template enemy objects. Now, these template objects have datablocks assigned to them of the form:

datablock t2dSceneObjectDatablock(Zombie_Mild_Homing)
{
   class = "ZombieClass";
   aggressionLevel = 1;   
   objectState = 1;
   // cut
};

However, I find it impossible to access functions with the "ZombieClass" namespace via the cloned object. I have read about various problems/issues people have had in the past regarding namespaces and cloning but I am confused on what the offical operation of this functionality is. *should* the cloned object be able to access it's assigned class? And if not, why not? If it should, is there anything I am doing wrong? The code I use to try and access the ZombieClass in my spawn behavior is below.

if (%clone.isMethod("init"))
   %clone.init();

Any ideas? Thanks in advance.

#1
03/02/2008 (6:03 am)
You could try:

if (%clone.isMethod("init"))
ZombieClass::init( %clone );

This is pretty much how I got around my cloned namespace problem, just an idea.
#2
03/02/2008 (6:04 am)
Actually, making it more robust - you could do the following

if( %clone.Class $= "ZombieClass")
ZombieClass::init(%clone);

That way you have a guarentee that the object is from the right class before you call the method.
#3
03/12/2008 (6:42 am)
Hi Brian, thanks for your reply, and apologies for the lateness of my own. I actually have done as you have suggested, I was hoping however that there was a solid solution to the problem. It seems quite strange to me that there is no way to ensure that clones share the same namespace as the template, I can think of many instances where I would want clones to execute the same code as their templates. Perhaps I am missing something.

I was sure I found a thread a while ago that stated that using datablocks and setting the class there would solve this issue, but doing so did not help me. o_O
#4
03/12/2008 (7:06 am)
I'm pretty new to TorqueScript, but not C/C++, so that was a solution that fixed it for me - but like you I thought it felt wrong. I guess I will search around for that post that you saw, because I would like a better fix than this myself.