GDC Max Scripting Class 2005 |
| Overview: | |
|
Script types: |
Description: - .ms, .mcr, .mse, .mzp |
| For Loops: | |||
For loops are used in conjuction with arrays, it is way to iterate through each item in the array and preform a task on that item. An array can be thought of a bucket of items, each item has a number in the array and can be accessed in any order that you need them.
The above example creates an array of string values and prints them to the listener and then returns the value OK to let you know that the code exited without errors. In this example x becomes equal to the indexed value of the array. This next example uses as iterative loop. Iterative for loop:
Notice that the result is the same as the previous one. In this example x becomes equal to each object in the array and not the index of the array. This is often used as a short had to the previous how ever isn't as flexable in some coding situations.
|
| Functions: | ||
Functions are a way of creating a reusable block of code. This block of code can be called from just about any where in the script and can be called from other functions. Functions give us a way to create none linear code. Arguments can be passed in to functions so that variables can passed on to them. Function with no arguments:
The value that is returned from a function is defined is the last line of the expression in the function. If no definable value is returned OK will be returned in it's place. Not having a value returned from a variable can make it hard to error check your code so it is always best to have your functions return a known value of some kind. Function that is passed one argument:
The variable x is passed from the for loop to the function and holds the one of the objects that is selected. The function sorts three bits of data and appends them to an empty array then passes that array back to the for loop. The format command prints that data to the listener and then the for loop continues with the next object. Example #1: 1 |
| Interfaces: | ||
Creating interfaces for scripts is an easy task and makes any script easier to use. Create a rollout and display it:
Rollout with UI items added:
|



