Page 1222 - Kitab3DsMax
P. 1222

Part XII: MAXScript and Plug-Ins
                                             result (15) in X. You can then see what is in X by just typing X in the Listener window and pressing Enter.
                                             Max then displays the value stored in X, or 15.
                                             You can name your variables whatever you want, and naming them something that helps you remember
                                             what each variable is for is a good idea. For example, if you want a variable that keeps track of how many
                                             objects you’re going to manipulate, the name “objCount” would be better than something like “Z.”
                                      Note
                                      Variable names can be just about anything you want, but you must start a variable name with a letter. Also, the
                                      variable name can’t have any special characters in it, like spaces, commas, or quotation marks. You can, however,
                                      use the underscore character and any normal alphabetic characters. n
                                             Variables can also hold strings, which are groups of characters. For example,
                                                  badDay = “Monday”
                                             stores the word “Monday” in the variable badDay. You can attach two strings together using the plus sign,
                                             like this:
                                                  grouchy = “My least favorite day is” + badDay
                                             Now the variable grouchy holds the value “My least favorite day is Monday.”
                                             Try this:
                                                  wontWork = 5 + “cheese”
                                             Max prints out an error because it’s confused: You’re asking it to add a number to a string. The problem is
                                             that 5 and “cheese” are two different data types. Data types are different classes of values that you can store
                                             in variables. You can almost always mix values of the same data type, but values of different types usually
                                             don’t make sense together.
                                      Note
                                      To see the data type of a variable, use the classof command. Using the previous example, you could type
                                      classof grouchy, and Max would, in turn, print out String. n
                                             Another very common data type is Point3, which represents a three-dimensional point. Following are a few
                                             examples of using points, with explanatory comments:
                                                  Pos = [5,3,2]        -- Marks a point at (5,3,2)
                                                  Pos.x = 7            -- Change the x coordinate to 7
                                                                       -- Now the point is at (7,3,2)
                                                  Pos = Pos + (1,2,5)  -- Take the old value for Pos,
                                                                       -- move it by (1,2,5) to (8,5,7)
                                                                       -- and store the new value in Pos
                                             In addition to these basic data types, each object in your scene has its own data type. For example, if you
                                             use classof on a sphere object, Max prints out Sphere. Data types for scene objects are actually complex
                                             data types or structures, which means that they are groups of other data types in a single unit. The pieces of
                                             data inside a larger object are called members or properties. Most scene objects have a member called Name,
                                             which is of type String. The Name member tells the specific name of that object. Another common property
                                             is Position, a Point3 variable that tells the object’s position.
                                             Max has a special built-in variable that represents whatever object is currently selected. This variable is $
                                             (the dollar sign), which is used in the following tutorial.

                                      1174
   1217   1218   1219   1220   1221   1222   1223   1224   1225   1226   1227