Maxscript (MXS) function &variable &argument

Trying to learn what does mean & symbol in front of variable name. MXS example would be:

-- Global variables (globals) can be accessed from any function at any given time
global head
 
-- We call our Read function
fn Read bitStream &head =

fn stands for function
Read is a function name
bitStream is a local variable (binstream type, it holds binary file inside itself for my example)
head is global variable
= (equal sign) shows function returns value? (though in Maxscript every function returns value anyway? It would be last expression which result will be returned as function return value if script writer does not specify function return value)

-- Read function which was called
fn Read bitStream &header =
 
(
)

My question is what does do & sign in front of &header?
Does &head (in first script example) indicate I pass global
variable to function Read?

I assume it indicates: "I am not ordinary function argument, instead I am a global variable!"
This script is written for 3ds Max 2010.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
InDesign's picture

Anubis your answer is pretty

Anubis your answer is pretty advanced, I like to thanks both of you for taking time for answering. I will look into "by-reference" variable. Making my first steps in maxscript (mxs).

Anubis's picture

by-reference

Yes, its MaxScript version of By-Ref concept (in programming languages). So nothing related to the scope (local/global) but to referencing/pointing values. In a functions it come in handy when you want multiple returns from 1 function, i.e. use them as in-out (most useful as 'out') arguments. In other words, if you modify by-ref variable into your function local body scope, then the original (pointered) variable is modified as well. Here is an example:

(
	local var = 0
	local ioError = -1
 
	fn exitCode num &ref = (ref += num; ref != 0)
 
	boolResult = exitCode ioError &var
 
	format "var = %\n" var --> now var is = -1
	format "has error = %\n" boolResult --> True
 
	if boolResult then -- if has error
	(
		format "Error#: %\n" var
		--OR
		case var of
		(
			-1: format "IOError!\n"
			default: format "UnhandledError!\n"
		)
	) else ( ... )
)

my recent MAXScripts RSS (archive here)

miauu's picture

Search maxscript reference

Search maxscript reference for "by-reference" variable.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.