PDA

View Full Version : why 2011 scripts not running in 2012?


floatingworld
06-25-2011, 05:13 PM
Could someone explain why the following function returns what is expected in max 2011, but not in max 2012?

fn getmorphchannelnumber Morphname =
(
for i = 1 to 100 do (

if (WM3_MC_GetName poly.Morpher i == Morphname ) then
(return i )
else if (WM3_MC_GetName poly.morpher 1 != Morphname) and i == 100 then (print (Morphname + " not found"))
)

Where Morphname is a string.

for example, in 2011, calling the function : getmorphchannelnumber "lFrown" yields a correct result, whereas in 2012, I get a "system exception".

Bobo
06-25-2011, 06:21 PM
Looks like return() is kind of broken in 2012, as far as I can tell.
It is normally implemented via an exception internally, and it looks like it is not being caught correctly for some reason.

For example, if you try

fn testReturn val =
(
for i = 1 to 100 do
if i == val then return i
OK
)
testReturn 50
-->testReturn()
-->** system exception **

I will report this to Autodesk, you should do the same.
In the mean time, don't use return()
In fact, you are discouraged from using it anyway, if you read the "How To Make It Faster" topics in the Help.

There are several ways to implement the same logic, for example
fn testReturn val =
(
local result = OK
for i = 1 to 100 do
if i == val do (result = i; exit)
result
)
testReturn 50

But the above uses Exit() which is not a good way to leave a loop either, so you could say instead

fn testReturn val =
(
local result = OK
for i = 1 to 100 while result == OK do
if i == val do (result = i)
result
)
testReturn 50

So in your case, you could try this:


fn getmorphchannelnumber Morphname =
(
local result = undefined
for i = 1 to 100 while result == undefined do
(
if (WM3_MC_GetName poly.Morpher i == Morphname ) then
(result = i)
else if (WM3_MC_GetName poly.morpher 1 != Morphname) and i == 100 then
(print (Morphname + " not found"))
)--end i loop
result
)--end fn

Keep in mind that your code was a bit off to start with, since the function only returned a value when the channel was found, but the return value when no channel was found wasn't exactly specified. Now you can call the function and then compare the return value with undefined and if it is not undefined, the channel was found and you will get its index...

floatingworld
06-25-2011, 06:31 PM
Thanks Bobo - very useful. I will report to autodesk. I will implement yr suggestion.

Bobo
06-25-2011, 06:40 PM
Thanks Bobo - very useful. I will report to autodesk. Isn't my code saying print :'Morph not found' , if the channel isnt there? Anyway, I will implement yr suggestion.

I only write the documentation, I don't develop the language. I sent an email to the developers to check if they are aware of the issue, but filing official bug reports is generally a good idea as the problem goes through the right channels.
Btw, I don't have the latest Service Pack installed, so I don't know if that changes anything.

gimik
07-08-2011, 10:07 PM
has anyone from autodesk addressed this in any way? i realize that maxscript's return() method was always a bit inefficient, but it seems crazy to allow it to break entirely--especially since it's worked fine for years.

we have quite a bit of code that relies on return()--is no one else as baffled by this as we are?

denisT
07-08-2011, 11:10 PM
has anyone from autodesk addressed this in any way? i realize that maxscript's return() method was always a bit inefficient, but it seems crazy to allow it to break entirely--especially since it's worked fine for years.

we have quite a bit of code that relies on return()--is no one else as baffled by this as we are?

I don't use return for many years. So, I don't have this problem.

Bobo
07-09-2011, 08:38 AM
has anyone from autodesk addressed this in any way?

Yes, it was fixed internally, but did not make it into the latest HF/SP for some reason.Hopefully in an upcoming HF. I made sure the developers are aware of the issue (they were already), but releasing updates is a tricky business with a product this size.

CGTalk Moderation
07-09-2011, 08:38 AM
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.