Notifications
Clear all

[Closed] dumb maxscript problem

So I’ve created a few scripts to make rigging a bit easier for me, and I thought ‘why not put some of these into functions so I can call them anywhere?’

so I created a function called f_CleanRig() and put it into my stdscripts folder.

Now I should be able to call that function in other scripts, however whenever I call the function in a script as follows:

            on btnCleanRig pressed do
         (
             f_CleanRig()        
         )

it throws an error telling me that f_CleanRig() is undefined. I thought the scripts in stdscripts auto loaded, so the function should be available to me. If I run it by typing the command into the command line, it works fine, so I know the function works, and I know it’s not getting loaded in the first place. What do I need to do to make sure it loads when max starts up?

thanks!

5 Replies

What you did should have worked.
Things to check:

*Does the file the function is saved in have .MS extension?
*Is the function itself in global scope inside the saved file?
*If you type the name of the function in the Listener without running your UI script, does it also complain about being undefined?

The function is saved in a .ms file, and it will work when i just type the command into the listener, however it does not have a global definition within the function. The function starts off like so:

function f_rigclean =
(
<script>
)
and is just saved as such. How do i make it a global function? I’ve tried putting ‘global’ at the top, and that gives me an error, as well as looking in the maxhelp to try and find out how to set it as a global function, but i seem to be lost

thanks!

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

If after you launch Max you type the function call into the Listener and it does work, then the .MS file was loaded correctly and the function IS global (the way you have defined it IS right, btw).
In that case, you have to make sure your other script doesn’t have a local definition with the same name somewhere in there, e.g.

(
 local f_rigclean
 ...
 )

If that were the case, the local variable would “hide” the global definition loaded from the StdScripts and your script would fail to see the global function. Alternatively, you can just add double-colon in front of the function call to enforce the search in the global scope only, e.g.

on btnCleanRig pressed do
               (
 ::f_rigclean()        
               )
 

WAIT A MINUTE!

What IS the name of your function really?
Once you typed f_cleanrig, once you typed f_rigclean

Is it possible you are just calling a non-existing one?

I’ve got the name of the function as f_CleanRig, and the rollout button is calling f_CleanRig, but i just noticed the name of the .ms file is f_rigClean.ms. I don’t think the ms file name should matter, as max should only load the function, but i changed it anyway, just for consistencies sake. after that change i reloaded and checked to see if the function loads, but it still does not.

however, I put the double semi-colon before the function call and that got the function to work, so i suppose i just needed to force max to look globally for the function.

thanks a ton for the help!