[Closed] MAXSript Anomalies
I am learning Maxscript, and I came across this little anomity:-
Type this into the MAXScript Listener:-
mybox = box length:20 wdith:20 Height:20
What does it create and why?
I know the spelling of “width” is incorrect but what I can’t understand is why it creates a box with those dimensions?
A
Try to put another argument at the end of the function called ‘coolness’, and set it to true. Prepare for something spectacular Hehehehe
Sure it has something to do with this, from the MAXScript help:
[left]Keyword Arguments. You write keyword arguments as a keyword:<value> pair, and they can appear in any order after the positional arguments. Functions can use some or all of their keyword arguments as optional arguments. If you call a function and don’t supply optional keyword arguments, they will have either the default value supplied by the called function, or the special value unsupplied when first referenced in the called function.
[/left]
So the property ‘width’ takes the last value that worked. I tried to use your sentence and varying the ‘wdith’ does not change anything in my new boxes…
[left]
[/left]
Thanks for the quick reply.
So if its not defined it uses a previously successful value, that makes sense.
When I added “coolness” the box changed colour is that correct?
Sorry you have to bear with me, I am only just above the “hello world” stage.
I did a little java and Perl at University but that was a long time ago!
Thanks again
Unless you tell Max otherwise (with the “wirecolor” argument, or by assigning a material), new primitives are assigned a random color at creation. So that was unrelated to the “coolness” argument.
Keyword arguments are just passed in. If the code of the function doesn’t use one, it won’t error, it’s just ignored. That’s why “coolness:true” does nothing.
He does, he is trying to ask “why does the box have a non-zero width eventhough I mistyped the keyword”.
The answer is that most optional keyword arguments provide a default value which is used if the keyword is not supplied. Thus, the box will be created with the default width if width: is mistyped, and not error will be thrown because wdith: is not expected and just ignored (as everybody else mentioned already).