Notifications
Clear all

[Closed] Function Booleans?

Is it possible to add #flags to a function like #Quiet?

 fn functionname var1 var2 #flag = 
(
	 if flag do print "hello"
)
 
 

input functionname 1 2 #flag
instead of :
input functioname 1 2 flag:true

6 Replies

Adding # in front of a variable classifies it as a name class in Maxscript terms. Try looking up the various documents on “Names” or “Name Values” in the Maxscript help. I think the issue is you need #flag (or (flag as name)) in your function and not just the flag variable.

Or am I totally missing what you are trying to do?

-Eric

I think what he’d like to do is be able to make his own functions that use common flags, like #face or #quiet, etc.

Currently you can just pass in those # values (they are passed in as names, as mentioned), but as to make them optional, I don’t think there is a way. You’d have to say

fn myFunction arg1 flag =
if flag == #quiet do print "shhhh...."

myFunction myArg #quiet

But if you didn’t pass in the flag, it’d throw an error.

Right Rob hit the problem on the head. I want optional variables that don’t have to be defined. I only want to know if they were called not giving them a variable.

Lots of built in functions have this but I can’t find any information on how to do it myself.

Hi Gavin,
you can add additional parameters to a function without the needing to define them during the call with the : (colon)


function sampleFunc var1 var2: =
(
	print var1
	print var2
)

sampleFunc "test1"
-- "test1"
-- unsupplied

sampleFunc "test1" var2:#test2 -- this is a "Name" variable but could be any datatype
-- "test1"
-- #test2

Both function calls are legal. You can perform a test on the “unsupplied” value.

  • Enrico
1 Reply
(@robgalanakis)
Joined: 11 months ago

Posts: 0

Still not really what the OP wanted. You still need to use the keyword argument (var2) to submit an argument, it isn’t really a ‘flag’.

On that thought, though, you could just have a generic “flags:” variable that takes an array of flags. Not the ideal solution, but probably as close as you can get.

Rob, you’re right, I’m sorry, I didn’t see that “instead of”. Gavin already considered and discarded my solution.

The only way I see to feed a function with an arbitrary number of arguments, is by using a single array, which holds values and optional flags too, but it’s absolutely not the solution to the current question.

You can also define a local variable to work as a flag higher in the scope, outside the function, and set it by hand before calling the function. This is not so good as well.

  • Enrico