View Full Version : Strange problem of Scope ?

11 November 2010, 01:48 PM
I have a strange problem with a macroscript which basically call a scripted render effect : monochrome.
The render effect is in the startup script directory and is visible in the add effect window.
The macroscript is executed via a toolbar button.
In the mcr I call the effect via the addeffect (monochrome()) command in the on execute event handler.

I launch max to be sure all variable are reseted.
When i run the script i receive :
Error Exception: -- Type error: Call needs function or class, got: undefined
OK, i can understand that the function monochrome() is undefined in the scope of the macroscript, but as the scripted effect is in the startup directory, the monochrome() should be global ?

Funny things : if i relaunch max (to reset again the variables), open the mcr in the editor and Evaluate it, after i can run it and evrything is fine.

After diging a while i came with this nasty workaround :
I create a simple script which contains the addeffect (monochrome()) command and call it in the mcr (instead of the command) with getfilein and again evry thing works like a charm except that i must create this nasty little script.

So why this strange behaviour which for sure is related to scope of variables ?


11 November 2010, 02:28 PM
the reason is quite logical. basically the macroscript is being defined before your startup script which means that "monochrome" will be interpreted as undefined in your macroscript. type "Startup scripts" in the reference search and click on the first result for info about the order that scripts are loaded.

to solve your problem you have 2 options.
1) add a double colon :: in your macroscript before ::monochrome like that. The double colon forces maxscript to look in the global scope for a variable by that name.
2) move your script to a location that gets loaded before the macroscripts as defined in the reference topic mentioned above

11 November 2010, 02:46 PM
Thanks, the double colon did the trick.
We learn each day :)

CGTalk Moderation
11 November 2010, 02:46 PM
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.