[Closed] Understanding a bit more about arrays
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
)
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.
That is simple and makes sense. That is super useful too. What would be a good examplein this case. Hiatus something simple.
Thanks.
John