In the previous lesson, you entered the string "Hello" in MAXScript, and MAXScript displayed the same string as its command output. When you enter other strings, MAXScript displays them and forgets about the previous ones. To make MAXScript remember the value of a string, assign it to a variable. The general syntax for assigning a variable in MAXScript is:
variable_name = variable_value
A variable_name starts with an alphabetic character or "_" (underscore), followed by any number of alphanumeric characters. The variable_value can be a string, a number, or any other expression.
To assign a string to a variable:
At the Listener prompt, enter the following command:
mystring = "This is my string."
MAXScript returns the value of the string variable:
You can now refer to this string variable by entering the variable's name. Enter mystring.
MAXScript again returns the value of the string variable:
This is faster than entering the string again. MAXScript remembers this string for as long as your MAXScript session is open, or until you change the variable's value.
To assign a new value to an existing variable:
Enter mystring = "This is not your string."
MAXScript now displays the new value of mystring:
When you refer to mystring now, MAXScript uses the new value. Enter mystring.
MAXScript now displays the new variable value:
Notice that MAXScript doesn't distinguish between lowercase and uppercase variable names because MAXScript names are not case-sensitive.
Next Topic