Variable function argument count or overloading?

Variable function argument count or overloading?

Anonymous
Not applicable
1,580 Views
4 Replies
Message 1 of 5

Variable function argument count or overloading?

Anonymous
Not applicable

So, is there any way to define a MXS function with variable argument count(like Format() is)?

Or maybe there's a way to overload them?

0 Likes
1,581 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Hi 3Doomer!

You can use positional parameters for variable argument count. Look at:

http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/files/GUID-6CF536D8-B90A-4998-AA16-71F23E710B4...

 

 

The parameters not defined are unsupplied oryou can set a default value for them.

 

You can overload functions:

 

fn function1 val1 val2 =

(

--code

)

 

fn function2 val1 val2 =

(

--different code

)

 

and you can use them as you need:

local function3 --undefined yet

if iskindof node GeometryClass then

  function3 = function1 --without () or arguments

else

  function3 = function2 --without () or arguments

--call the correct function

function3 valueForVal1 valueForVal2

 

0 Likes
Message 3 of 5

Anonymous
Not applicable

 

) I don't want to define my function with 100 or more positional parameters because it looks kinda wrong. And it'll be unconvenient to call them, because I must provide a name for every parameter on call. Of course, I can pass an array, but it'll hurt performance and grow up memory consumption.

I know that MXS DO have such abilities(Format(), for an example). But it's still not clear how to create my own functions with such abilities.

 

2) Your last code's kinda "dirty hack" and it can hurt performance in some cases. Also, it's not very clear to read and understand...

 

"Common" languages(as C++/C# for an example) have good mechanisms of overloading and variable argument count functions...I just wanna know if there's a legit way to do something like that in MXS.

 

0 Likes
Message 4 of 5

Anonymous
Not applicable

I think "Format" is not a maxscript function. It´s a C++ function that you can call in maxscript.

It´s defined in the sdk include/maxscript/protocols/primitives.inl

 

You can create your own C++ functions and have it visible from maxscript, but then, it's C++ and not maxscript.

http://docs.autodesk.com/3DSMAX/16/ENU/3ds-Max-SDK-Programmer-Guide/files/GUID-016E96CE-F224-458D-9A...

 

 

1) maybe you can use a struct, or array member inside a struct, if I don't remember wrong, maxscript always past structs as pointers. And yes, 100 positional parameters looks kinda wrong.

 

2) can you give me an example for hurt performance? I didn`t use it a lot but it saves me sometimes. And I use it for improve performance:

GetMapFace = polyop.getMapFace

http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/files/GUID-74BA7105-9907-4BB2-8C39-D9FD147C489...

 

when you know how to do it, share it!:)

0 Likes
Message 5 of 5

Anonymous
Not applicable
I'm using a lot of tips from MAXScript reference to improve performance...

I have a function that prints variable count of arguments to a custom data buffer based on string array, that can be written into the file using .NET(<some system dotnet class>.WriteLines method).
Of course, I can do a StringStream(I'll be able to use Format() to write my values into lines) array instead of String, but that method can't work with StringStreams...
0 Likes