View Full Version : Understanding a bit more about arrays

03 March 2012, 03:11 PM
I've got across a few scripts here online which ran arrays through a function which the function contained a for-loop inside of it.

I was wondering if someone could better explain or reference a document that would help me understand why there is a "&" by the array. What does that exactly control or do.

myArr = ($box001,$box002,$box003)

fn doingStuff arr = (
for obj in arr do....

on button pressed do (
doingStuff &myArr

03 March 2012, 03:44 PM
The ampersand operator means that a parameter is passed as a reference.
Assume the loop in the doingStuff function modifies the array. If you pass myArr to the function 'normally', without the &, the array will be modified in the local scope. myArr will remain unchanged. If you pass it with the &, myArr will be changed.

This is not specific to arrays by the way, it applies to any maxscript variable.

Also, the example code won't work, since arr is a reference, so you have to dererefence (*) it to be able to loop through it.

03 March 2012, 04:25 PM
That is simple and makes sense. That is super useful too. What would be a good examplein this case. Hiatus something simple.

CGTalk Moderation
03 March 2012, 04:25 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.