Softlight Scripted Plug-in

USER QUESTIONS AND ANSWERS


Q : Why is the () placed after the line "helix_path.transform.controller = lookat()"

A: When creating an object, you have to call its "constructor" function.
Usually you also send some data about what properties to be set, too.
For example, typing in

b = box pos:[100,0,0]

will construct a new default box at the specified position.
But every parameter of such an object has a default value, so sometimes you don't intend to provide ANY information about parameters, just create a default object.
In such a case, you have to use the () to denote "no parameters, but still a function call":

b = box()

will create a default box at default position [0,0,0]

In our case, the lookat() constructor simply creates a default lookat controller without supplying any information about user preferences (axes to align or whatever).
That explains the ()
 

Same case when you define an own function and it takes no parameters.

fn hi_function = (print "Hi Mike!")

To call this function, I just have to say

hi_function()

and it will be executed. Without the () typing

hi_function

would access the variable containing the function itself, not the content stored in that variable...
 

A function that requires parameters will be called with a parameter instead of the ()

fn hi_function name_to_greet = (print ("Hi "+name_to_greet))

hi_function "Mike"

In this case, "Mike" is the parameter that is supplied to the function and used to build the final output string.
Because print always expects a single parameter, I had to put brackets around the string construction ("Hi "+name_to_greet)
so maxscript first evaluates what is inside, then prints the result...