Problems assigning default values to variables in a function

This is my first post, so I honestly apologize if I'm doing something wrong...

I'm new at MAXscript and I've got a little problem trying to assign default values to variables in a user function. Let's just take the example MAXscript help provides:

   function sign val:0 =
   (
   if val == 0
   then messagebox ("Equal to 0")
   else if val > 0
   then messagebox ("Greater than 0")
   else messagebox ("Less than 0")
   )

Simple enough... opening a New Script window, copying/pasting it there, evaluating it and checking for the results at the listener is says "sign()... OK"
But if I try to use this function typing, for instance

   sign(5)

the answer is:

   -- Argument count error: sign wanted 0, got 1

if I remove the syntax for the suposedly default value on the first line, like that:

   function sign val =
   (
   if val == 0
   then messagebox ("Equal to 0")
   else if val > 0
   then messagebox ("Greater than 0")
   else messagebox ("Less than 0")
   )

it now works fine if I say "sign(-5)", but inputing a value is now mandatory and if I type only the function without providing values for the parameters, it gives an error message like

   sign()
   -- Argument count error: sign wanted 1, got 0

It seems that if I do provide a "default" value to the function variable doesn't get it anymore. I suspect that my mistake is evident but it scapes me.
And, by the way, I also strongly suspect that this question is faaar too "newb" to be here, is there a more appropriate place for people who's just starting on MAXscript?
Thank you very much!

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
colinsenner's picture

In Maxscript you'll need to

In Maxscript you'll need to pass the optional variable 'val' in this instance, try (for the first instance with the optional variable)

sign val:5

or for the second

sign 5

This is the correct way to do it.
-Colin

Christopher Grant's picture

Welcome to

Welcome to ScriptSpot!

Interesting catch. I haven't noticed this behavior before but I'm getting similar results here. I was perusing the MAXScript help under "Function Parameters" and unless I'm missing something - its saying you should be using var:value as the syntax for default function values which is exactly what you're doing...

Anyone else have any ideas?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.