Variables and Math Functions

MAXScript is located in the Utilities Panel. When initiated, the following options appear:

Open Listener - Opens the Listener window, which is the place you type the commands.

New Script - Starts a new script, opening a Notepad-like editor.

Open Script - Opens a script in the text editor.

Run Script - Executes a script file.

Utilities - Allows the user to select among loaded scripts.

All commands, variables, etc. can be declared directly in the Listener, or can be written using the New Script option, or still can be created using Notepad, and executed using the Run Script option.

  • Open the Listener and type b = 1 and press SHIFT+Enter.

Variable declaration in MAXScript is done typing the variable name and its value. Variables can be letters and numbers (alphanumeric), but must start with a letter, with the exception of the special characters (%*&...) and built in functions. Variable names cannot have spaces.

Variables can be:

Integer numbers - 1,10, -5, 3876
Float numbers - 0.1, 0.0542, -358.245
Text (strings) - "abc", "text example"
Points (point3) - [25,30,15]
etc.

After typing something in the Listener, you must execute the code for the script to run. To do so you can use SHIFT+Enter, or you can press the Enter key in the Number Keypad. Simply pressing Enter might not work if not at the end of the line of code in the Listener. Every time you are asked to enter something in the Listener in any of these tutorials, that means you are evaluating this series of commands.

  • In the Listener, type c = 1.5 and type d = b + c

Math functions are executed directly, just like variables definition.

Math functions can be:

<operator> + <operator>
<operator> - <operator>
<operator> * <operator>
<operator> / <operator>
<operator> ^ <operator> -- exponential
<operator> as <type of variable> -- conversion between variable types

All arithmetic rules apply (parenthesis and precedence, where multiplication takes place before subtraction).

Examples:

2 + 5.4 = 7.4
2 + 2 ^ 4 = 18 (^ precedes the addition)
(2 + 2) ^ 4 = 256 (the parenthesis define the precedence)
3 * sin 256 (sin function used in a formula)
23.65 as integer = 23 (variable type conversion)

This tutorial might seem theoretical but these fundamentals are crucial for learning how to work with MAXScript.

Alexander Esppeschit Bicalho © 1999