Game Development Community

addProtectedField clarification

by elvince · in Torque 3D Professional · 02/23/2011 (12:23 am) · 1 replies

Hi,

I just need a clarification on addProtectedField.

my understanding:
When a variable is set, it will call the set function. If it return true, then the value is set, if false, it's not set.

Pretty straight forward :D

In gamebase:
in the set function you can find:
if( Sim::findObject( db, data ) )
return object->setDataBlock( data );

So if the setDatablock return true, the variable is updated twice. One time in setDatablock and once when return true.

Did I miss something?
I did make a test on my own class, and if you return true, the datablock variable is set correctly. So what is the use of setting it twice? may be some old code... but I think it worse to be clear ^^

#1
02/23/2011 (12:51 pm)
There are probably things going on in setDataBlock that need to be performed whenever the datablock is changed, such as firing the onNewDataBlock callback. It's a bit redundant to set it twice, you're right. I've used this trick myself to auto-update objects whenever you change a member field, without having to call an actual function on the object.