Optional parameters in UDF

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

Optional parameters in UDF

Post by xavram »

Is there a way to set up the macro so that some of the incoming arguments are optional?

IE, "SetDamage" takes a targetId, damage value, and "isCrit"....but in some scenarios, "isCrit" wouldn't be passed in and should (in those circumstances) default to false.

Right now, if I put 3 paramters in a UDF macro and I try to call it with only 2, I get an error saying, "3 parameters expected".

Is there a way to set this up?


xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

Re: Optional parameters in UDF

Post by xavram »

Oh, excellent...thanks Wolph!


User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Optional parameters in UDF

Post by aliasmask »

Maybe it's just a programming style, but I use >= rather than ==. But it depends on how you write the statement.

Code: Select all

[h, if(argCount() >= 1): first = arg(0); first = "default"]
[h, if(argCount() >= 2): second = arg(1); second = "default"]
[h, if(argCount() >= 3): third = arg(2); third = "default"]
if you use argCount()==3 then everything would be set to default except the 3rd argument. Just something to be aware of.


User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Optional parameters in UDF

Post by Full Bleed »

aliasmask wrote:

Code: Select all

[h, if(argCount() >= 1): first = arg(0); first = "default"]
[h, if(argCount() >= 2): second = arg(1); second = "default"]
[h, if(argCount() >= 3): third = arg(2); third = "default"]
This looks like WIKI relevant material. ;)
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

Post Reply

Return to “Macros”