Search ProofOfProgress Blog

Tuesday, April 12, 2011

L01:Global Pitfalls In MaxScript

Download Source Files to Follow along with lecture:



Summary of video coverage:
[1]: Globals in MacroScripts are not quite what they seem.

[2]: GlobalVars.Remove is potentially hazardous.

[3]: Checking to see if an object exists by using:
if(theObj==Undefined)then(.....)
IS NOT THE COMPLETE SOLUTION.



[Source Files Below] Download Source: ****HERE****

2 comments:

  1. Actually, if testing for a deleted scene node you can just replace the whole try-catch part with "isDeleted KX9" test. As for the GlobalVars.Remove part, while it might be (in some scenarios) useful in regular scripts what's the point if used in macroscripts that become an integral part of the program anyway and not leaving a trace is not a real option? If it's just to have a button on a toolbar, you can as well have "on execute do fileIn .." in the macroscript to call it and if you wouldn't use the globals in the script as scene node containers you could skip the global test/declaration completely in favor of something like ::KX9 = FN01.

    If the concern is that some other script could overwrite your globals and/or you need to use quite a lot of them at once, what you can do is to make a global struct that gets loaded first (either via startup.ms or better yet stdscripts/*.ms) where you have all your varaibles at once place and can access them easily, let's say like JMIMtools.KX9 (or ::JMIMtools.KX9 to save time otherwise spent looking for locals of that name).

    Take that only as improvement suggestions, though, it's not a critique of what you do in any way.

    ReplyDelete
  2. I was not aware there was an "isDeleted" command in max.

    I like that solution much better.
    As I only use try/catch as a last resort.

    Thankyou for the input!

    ReplyDelete