PDA

View Full Version : startup .ms definitions work in ms listener but not in mcr (undefined)


erik_j
08-23-2007, 11:36 PM
I just did another script first time since max 9 and I have this weird error with an mcr that runs a function in a struct loaded to a button.
the struct and its function are defined in a .ms file in the startup folder (tried both in local settings\application data\autodesk\... and under max program folder).
it works only on the occasion when I start up max without the mcr loaded as a button and then add it anew.
if I then exit max and open max again the button will be there since I added it last time but now the button won't have access (or something?) to the defined struct and function even though they were defined on startup as the ms file loaded fine. I can call the function from the script listener.
but if I would've removed the button before I exited and added it again when I launched max again then it will work fine.
if it's relevant I add the button by dragging the macro from the customize ui actions list to the toolbar.

anyone know how to solve this?

I guess the error might be in my scripts so here they are: nim_rename_mirrored.zip (http://nim.pansarvagn.net/nim_rename_mirrored.zip)

Bobo
08-24-2007, 12:03 AM
As the MAXScript Reference explains, functions that will be published for use by other scripts like MCRs should be put into the StdPlugs\StdScripts folder, or any plugin folder.

The Startup folder is one of the last things to be evaluated and at that point it is probably too late because the MCRs could not find the global definitions and would have created local undefined variables with the same names instead.

See "Startup Scripts" topic in the Help.

Another way to work around this is to declare the variable names of functions or structs that a script intends to use as global in the beginning of the MCR, so if the MS comes later, it would find the existing global variable names and would "populate" them with the correct values. This is similar to pre-declaring variables to be visible by rollouts defined later in the code, but in general is a poor workflow if you have hundreds of functions you want to access that have not been defined yet. If you are putting your functions inside a single global struct, that might work though.

erik_j
08-24-2007, 01:36 AM
thanks alot, Bobo!
lucky I asked or I'd have continued not understanding the startup folder.
good points, I know how I want to do it now :)

CGTalk Moderation
08-24-2007, 01:36 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.