What is the difference between 'undefined' and 'unsupplied' values?

MAXScript Frequently Asked Questions

The undefined value is assigned to any variable or array element that has been declared but has not been assigned a value yet.

If you create a variable 'a' but do not use the assignment operator '=' to store a value in the variable, its initial value will be 'undefined'.

For Example:

a

a == undefined

Result:

undefined

true

Also, if you create an array and assign a value to an element with index 4, all 3 elements before the one you assigned to will be initialized implicitly to the value 'undefined'. These values are like "placeholders" because you cannot have an array with the 4th element set to a value but without 3 elements before it being initialized.

For Example:

a = #()

a[4] = "Yeah!"

a

Result:

#()

"Yeah!"

#(undefined, undefined, undefined, "Yeah!")

The unsupplied value is assigned to function parameters that have not been supplied when the function has been called.

A function can be called with no parameters (in this case, a pair of parentheses is required to denote 'no parameters'), one or more arguments, plus one or more named arguments. The arguments defined by the function are compulsory and have to be supplied. The named arguments on the other hand are optional and can be omitted. In such cases, the programmer could compare the named argument's value with the 'unsupplied' value to find out whether a meaningful value has been sent or has been omitted.

In the following example, the function expects no arguments or one optional named argument. It will check whether the named argument has been supplied and print a respective message to the Listener, then return true or false.

For Example:

fn test_function thePrameter: =

(

if thePrameter == unsupplied then

(

print "How about providing a parameter?"

false

)

else

(

print "Thank you for calling the function with a parameter!"

true

)

)

 

test_function()

"How about providing a parameter?"

false

test_function theParameter:123

"Thank you for calling the function with a parameter!"

true

See also

Undefined Value

Unsupplied Value

Creating Functions

Function Calls

When do I use () after a function?

Frequently Asked Questions