OK, I'll try to explain.
Maya only compiles scripts it needs, at the moment that it needs them. This is for performance reasons.
The way scripts are compliled by Maya is by using the source command. Docs here.
Calling source actually compiles and executes the contents of the script. When this happens, all functions that exist in the script are created in the Maya runtime environment, making them "available" to call. So you can call any global function from that script once its been sourced.
There is also a clever shortcut built into Maya which allows you to name a function in a script with the same name as the script. If you do this Maya detects it at startup (different to sourcing). All you have to do is call the name of the script/function and Maya will actually source the entire script at that point.
So in the example below:
<File://MyFunctions.mel>
global proc Func1() {
print "Function 1";
}
global proc Func2() {
print "Function 2";
}
global proc MyFunctions() {
print "Main Function Has Been Run!";
}
</File>
Assuming this file were in your MAYA_SCRIPT_PATH, you would get the following results:
Func1();
// Error: line 1: Cannot find procedure "Func1". //
This is because the script wasn't sourced. So you need to either source the script:
source MyFunctions;
or just call the main function:
MyFunctions();
// Result: Main Function Has Been Run!
Now all of the functions are available from the script:
Func1();
// Result: Function 1
Func2();
// Result: Function 2
I hope this helps to clarify things
Mike