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:
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:
but if it were something more complicated might not be.
i guess i'm looking for implicit setter/getter action.
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.
About the author
Torque 3D Owner Stephen Zepp
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!