error using function the second time in for loop

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  06 June 2010
error using function the second time in for loop

Hi,

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:


fn FindTimeRange =
 (
    ...
    --some simple stuff finding time ranges, first and last keyframes
    ... 
   -- here I'm "storing" output values into the function
   FindTimeRange = #(OrigTimeStart, OrigTimeEnd, CT, MaxTimeStart, MaxTimeEnd)
 )
 
 for I=1 to 3 do
 (
 ...
 -- running the function and loading it's values into other variable... I think I'm doing something wrong here
 TimeRanges = FindTimeRange()
 ...
 )


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
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.
fn FindTimeRange =
(
    FindTimeRange = #(OrigTimeStart, OrigTimeEnd, CT, MaxTimeStart, MaxTimeEnd)
)

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:
fn FindTimeRange =
(
    #(OrigTimeStart, OrigTimeEnd, CT, MaxTimeStart, MaxTimeEnd)
)


Hope that helps,
Martijn
 
  06 June 2010
Eh, shame on me, should have figured that out.
Thanks a lot.
 
  06 June 2010
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 02:11 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.