Page 1226 - Kitab3DsMax
P. 1226

Part XII: MAXScript and Plug-Ins
                                             The or operator is similar to and, except that an expression with or is true if either of the expressions is
                                             true or if both are true. Here are some examples:
                                                  (2 > 3) or (2 > 1)     -- even though (2 > 3) is false, the
                                                                         -- entire expression is true because
                                                                         -- (2 > 1) is true
                                                  (2 > 3) and (2 > 1)    -- false because both expressions are
                                                                         -- not true
                                             Try some of these complex expressions to make sure that you understand how they work:
                                                  a = 3
                                                  b = 2
                                                  (a == b) or (a > b)    -- true because a IS greater than b
                                                  (a == b) and (b == 2)  -- false because both expressions are
                                                                         -- not true
                                                   (a > b) or (a < b)     -- true because at least one IS true
                                                  (a != b) and (b == 3)  -- false because b is NOT equal to 3
                                             The not operator negates or flips the value of an expression from true to false, or vice versa. For example:
                                                  (1 == 2)               -- false because 1 is NOT equal to 2
                                                  not (1 == 2)           -- true. ‘not’ flips the false to true
                                             Conditions
                                             Conditions are one way in which you can control program flow in a script. Normally, Max processes each line,
                                             no matter what, and then quits; but with conditions, Max executes certain lines only if an expression is true.
                                             For example, suppose you have a script with the following lines:
                                                  a = 4
                                                  If (a == 5) then
                                                  (
                                                   b = 2
                                                  )
                                             Max would not execute the line b = 2 because the expression (a == 5) evaluates to false. Conditional
                                             statements, or “if” statements, basically say, “If this expression evaluates to true, then do the stuff inside the
                                             block of parentheses. If the expression evaluates to false, skip those lines of script.”
                                             Conditional statements follow this form:
                                                  If <expr> then <stuff>
                                             where <expr> is an expression to evaluate and <stuff> is some MAXScript to execute if the expression
                                             evaluates to true. You can also use the keyword else to specify what happens if the expression evaluates to
                                             false, as shown in the following example:
                                                  a = 4
                                                  if (a == 5) then
                                                  (
                                                   b = 2
                                                  )
                                                  else
                                                  (
                                                   b = 3
                                                  )

                                      1178
   1221   1222   1223   1224   1225   1226   1227   1228   1229   1230   1231