|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Working with VariablesVariables are simply containers that hold a value, property, etc. Why do you need variables? To make scripting fluid and customizable. For instance, you can make a script to find out whether the current temperature is hot or cold. This script would compare the current temperature with a certain value. If the current temperature is below, say, 30, it is cold. Doing this as a script, you would have a variable, called temperature, which you would compare to another variable, named cold, and this comparison would tell you if it is cold or not. Using this method, you can easily change the values of either variables and re-run the script over and over. Variables are also useful because they allow you to know what property you are using, which is convenient when you are working with the name of the property, not the property itself. Suppose you need to access a property in a diffuse map of an object. To do it in MAXScript, you would need to use object.material.diffusemap .property. If you assign a variable = object.material.diffusemap, you will save time using just variable.property in the future.
If you compare MAXScript to other programming languages, it is very easy to assign variables in MAXScript. Almost every programming language requires you to declare variables, variable types, even the amount of memory to be used. In MAX-Script, you dont need to do anything like this. Assigning VariablesAssigning variables is simply done by entering a value for the variable. And you can use any kind of valuea number, a property, a string of text, etc. You can use any name for a variable, excluding some names used by MAXScript commands, special characters, and spaces. A variable name can also have numbers, but it must start with a letter. Here are some of the most common types of variables you can assign in MAXScript.
You can assign an integer value to a variable, and later in the script you can assign a different value, which doesnt need to be an integer. This is different from many programming languages, where you cant automatically change a variable type once its assigned. Very few operations can be done mixing variable types. Now you will assign some variables so you can see how its done in MAXScript:
Performing Math OperationsMath operations are performed the same way variables are assigned, simply by typing the math formula, for example, z = x + y. All math rules are respected in MAXScript, which means that you can use parentheses and the precedence rules. That is, data in parentheses will be evaluated first, then exponential operations, then multiply and divide, and finally, addition and subtraction. Suppose you have the two following examples: 2 * 3 + 4 and 2 * (3 + 4). In the first instance, MAXScript will first calculate 2*3 and then add 4. In the second one, MAXScript will first calculate 3+4 and then multiply the result by 2. Performing Basic Math OperationsLets work with some variables and basic math operations to get a feel for how MAX handles these functions.
© 2000, Frol (selection, edition, publication) |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|