|06 June 2010||#1|
just a humble animator
Join Date: Apr 2006
error using function the second time in for loop
I have a function which searches for the first key and last key of selected objects. I'm then returning array of time range start, end, first key time, last key time and slidertime.
I'm calling the function inside for loop. Problem is that everything works correctly in the first cycle, but will crash with an error on the second loop (Call needs function or class, got.
Here is how my script looks like:
First loop runs ok, but the second loop will crash with this error:
-- Type error: Call needs function or class, got: #(0f, 14f, 14f, 0f, 26f)
In maxscript editor cursor stops on TimeRanges = FindTimeRange()
I'm getting that error even if I manually execute single line which tries to run the function and load it into variable.
I think that I'm doing something wrong with trying to load function into variable part of the script, but can't figure out what it is or what should I do different.
Any help would be appreciated.
|06 June 2010||#2|
Martijn van Herk
VFX Technical Director
Join Date: Jun 2002
I'm guessing you've used Visual Basic before, where this is how you have a function return a value. In maxscript it works a little different though.
When you create an mxs function like above, max basically creates a variable (in the above case FindTimeRange) which contains a pointer to the actual function. So FindTimeRange() calls the function.
The second line in the above script overwrites that function definition with the array, so that's why it fails when you try calling it again. The second time the variable no longer points to the function, but to the array.
A maxscript function always returns the last value that was used in the function, so you can simply change it to:
Hope that helps,
|Thread Closed share thread|