Game Development Community

Why pass object ID to datablock methods?

by N.K. · in Torque Game Engine · 07/12/2009 (12:50 pm) · 2 replies

Hi,
Since datablocks are static and any changes made to them are nor transmitted to the clients, why do we
need to pass the id of the object as the second argument of all datablock methods? Its not like the data will be different for each object using the datablock. Can't we just pass the datablock id?

Or is it that the object id is not used to identify the datablock, rather it is used to call functions on the object based on the data in the datablock?

Regards,
N.K.

#1
07/12/2009 (9:43 pm)
Quote:
Or is it that the object id is not used to identify the datablock, rather it is used to call functions on the object based on the data in the datablock?

that sounds about right.

Quote:
why do we need to pass the id of the object as the second argument of all datablock methods?

This has to do with how the torque engine implements datablock methods. The scripting interface makes certain assumptions about the order of parameters passed to datablock functions as well as object functions. In particular, it will assume the first parameter is the datablock and the second parameter is the object handle. Thus, technically you arent actively "passing in" those values so much as you are complying with how torque works.
#2
07/13/2009 (10:19 am)
> Its not like the data will be different for each object using the datablock.

true, the data in the datablock won't be different but the object referencing the datablock will.

say you have a datablock MyDataBlock and fifty object instances all referencing it. any method in the datablock which is expected to act on an object referencing it clearly needs to know the ID of the object.

eg:
datablock MyDataBlock
data data data

object instance Object1
datablock = MyDataBlock

object instance Object2
datablock = MyDatablock