Game Development Community

Engine-side callback when scriptObject field is set ?

by Orion Elenzil · in Torque Game Engine · 02/01/2007 (9:37 am) · 2 replies

Hey all.

so when i expose member fields to script via addField,
sometimes i'd like the object to get a callback when that field is touched by script.

for example,
i have an object with a "visibleDistance" parameter.
eg:
addField("visibleDist"       , TypeF32     , Offset(mVisibleDist       , Gui3DProjectionCtrl));
for efficiency, since i'm testing it every frame, i'd like to actually store and test against mVisibleDistSquared.

so i'd like to update mVisibleDistSquared whenever script updates mVisibleDist.

AFAIK, the only way to do this is with a setter/getter such as setVisibleDist().

- which is fine, i'm just curious if there's a mechanism i'm missing out on.

you know how i hate to miss out on mechanisms.

tia,
ooo

edit:
alternatively, the test could be this:
if (distSquared < mVisibleDist * mVisibleDist)
which would actually probably be totally fine in this example,
but if it were something more complicated might not be.

i guess i'm looking for implicit setter/getter action.

#1
02/01/2007 (9:48 am)
Interestingly, I just learned of a technique that is being used more and more in TGB that does pretty much what you are discussing, but I don't know it well enough yet to explain it fully.

In effect, it's exactly what you are mentioning: implicit accessor methods that are called/utilized when script changes a persistent field. I'm not 100% sure that it will meet what you are discussing, but as soon as I get some time to grasp best practices, I'll get back to you!
#2
02/01/2007 (9:52 am)
You rock, Stephen.