tShrinkTimeOut = new timeout("ShrinkTimeOut" + string(the milliseconds),
5, "fShrinkLoop", mModel);
Below is a function I am using to scale an object down and then hide it. It works fine on just one object, but if I try to run it on multiple objects at the same time, only the last object gets scaled down. I believe this is because the timeout list only ever has a single item in it, ?ShrinkTimeOut?. Does each entity in the timeout list need a distinct name? And if so, how would I dynamically generate a name and save it so I can kill the timeout object once the object has scaled down fully? //JavaScript ...
Below is a function I am using to scale an object down and then hide it. It
works fine on just one object, but if I try to run it on multiple objects at
the same time, only the last object gets scaled down. I believe this is
because the timeout list only ever has a single item in it, ?ShrinkTimeOut?.
Does each entity in the timeout list need a distinct name? And if so, how
would I dynamically generate a name and save it so I can kill the timeout
object once the object has scaled down fully?
//JavaScript:
//Scales an object over time.
//mModel must be of the format: member("ModelName").getPropRef("model", 1)
function fShrinkModel(mModel) {
//Creates a timeout object.
tShrinkTimeOut = new timeout("ShrinkTimeOut", 5, "fShrinkLoop", mModel);
}
function fShrinkLoop(mModel) {
//Creates a variable that contains the vector value of the model's scale
(vector( 1.0000, 1.0000, 1.0000 )).
nScaleVector = mModel.getPropRef("transform").scale;
//Checks to see if the model is 1% or less than its original size.
if (nScaleVector[1]<=0.01) {
//Makes the model invisible.
mModel.visibility = symbol("none");
//Kills the timeout object.
tShrinkTimeOut.forget();
} else {
//If it is not, we scale the model down further and allow the loop to
repeat.
mModel.scale(0.9);
}
}
tShrinkTimeOut = new timeout("ShrinkTimeOut" + string(the milliseconds),
5, "fShrinkLoop", mModel);
Thanks for the response, Sean.
Does it look like I am getting rid of the timeout object properly in my code?
I was trying to use forget with tShrinkTimeOut and not ?ShrinkTimeOut?.
A broader question- does this look like a good method of scaling an object
down over time? I need to shrink objects to (0, 0, 0) and would like to wrap
it into a nice little function. Any thoughts?
> Does it look like I am getting rid of the timeout object properly in my code?
Now that you mention it, and I have a look, no - it doesn't:
//not sure of the order of parameters here:
function fShrinkLoop(mModel, aTimeout) {
//Creates a variable that contains the vector value of the model's
scale (vector( 1.0000, 1.0000, 1.0000 )).
nScaleVector = mModel.getPropRef("transform").scale;
//Checks to see if the model is 1% or less than its original size.
if (nScaleVector[1]<=0.01) {
//Makes the model invisible.
mModel.visibility = symbol("none");
//Kills the timeout object.
aTimeout.forget();
} else {
//If it is not, we scale the model down further and allow the loop to
repeat.
mModel.scale(0.9);
}
}
Sean, that's exactly what I needed. Thanks for your help.
Bookmarks