How do I pass an array as function argument
Hi there,
want to know how I can pass an array as an argument for a max script function.
I currently try it like this. but I get an error 'No "append" function for Global:myarray':
fn myfunc arr =
(
--do some stuff with array
append arr 3
)
myarray=#(a,b,c,d,e)
myfunc &arr
When I leave the reference symbol away the variable arr in myfunc becomes "undefined".
So how do you do that kind of stuff done right? Or is that not possible in max script?
Comments
search for "by reference" in the help
I think you need function with "by reference" variable. By default all function parameters in MaxScript are ByVal (i.e. pass a copy of the value), not ByRef (we marked explicit with '&' sign). And for example:
But... using function:
So, you still can assign the result of your function to your initial array like this:
myArr = myFunc myArr
Or if you want start using ByRef, then here is an example:
Ah, and as all functions always return result, using ByRef you can combine to make your function return multi-results. Here is an illustration --
Hope this helps, Cheers!
my recent MAXScripts RSS (archive here)
thx miauu, yeah I tried that
thx miauu, yeah I tried that too but didn't work somehow. anyway I did it another way now, but thanks anyways
( fn myfunc arr = ( --do
(
fn myfunc arr =
(
--do some stuff with array
append arr 3
)
arr = #()
-- myarray=#(a,b,c,d,e) -- #(undefined, undefined, undefined, undefined, 2.71828)
myfunc arr
)
Tools and Scripts for Autodesk 3dsMax