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

MAXScript FAQ > What is the difference between 'undefined' and 'unsupplied' values?

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 4 th 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 theParameter: =
(
 if theParameter == 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