Trouble with using UDF in a "if" roll

19 views
Skip to first unread message

Arsil PS

unread,
Nov 20, 2018, 2:13:05 AM11/20/18
to idle_...@googlegroups.com
Hello.

I have a macro called canReactMacro which returns 1 is the selected token can use a reaction, if it can't it prints the reason and returns 0.
This macro seems to works fine.

I've defined a user defined function (this might be an obsolete phrase now) called canReact to call it in the OnCampaignLoad of a lib token.
Here's the definition:
[h: macro.define("canReact", "canReactMacro@Lib:MacroHelper", 0)]

Now, in a token macro, if I do this:
[macro("canReactMacro@Lib:MacroHelper"): 1]
[if(macro.return==1),Code:
{        
   
[h:state.ReactionUsed=1]
   
Defensive Duelist FEAT: [r:token.name] uses a reaction vs a melee attack getting a +<b>[Proficiency]</b> bonus to AC for that attack.
}]
It works correctly, but if I do this:



[if(canReact()),Code:
{        
   
[h:state.ReactionUsed=1]
   
Defensive Duelist FEAT: [r:token.name] uses a reaction vs a melee attack getting a +<b>[Proficiency]</b> bonus to AC for that attack.
}]

I get

Invalid condition in IF(canReact()) roll option.

If I use 
[if(canReact()==1),Code:

It suppresses the output from the canReactMacro (which writes on chat the reason why you can't use your reaction).


My goal is to be able to use "canReatc()" (possibly without "==1") in the if condition and not having the output suppressed.

Note: these macros were not in the framework I've posted recently, I thought it was something generic and didn't
upload something to test, but I'll gladly do it if needed.
What am I doing wrong? Is there a better way to handle it?

EDIT: I guess it can't be done because I'm calling the macro inside the "if".
Well, I'll use the first solution if there isn't a more elegant solution.

Idle Ideas Inc.

unread,
Nov 23, 2018, 3:51:11 AM11/23/18
to Home of our Idle Ideas
IIRC, you can't make such calls, even in MT. In the parser, there's a hack that switches out an expression to something like "value == anothervalue", which IIRC, doesn't allow what you're trying to achieve

DeadMeat

unread,
Nov 23, 2018, 3:13:25 PM11/23/18
to idle_...@googlegroups.com
if(canReact()) validity is dependent on the return value from the UDF. If you show that code, we can see the problem. If you don't send back a number, "true" or "false" it will throw an error.

if() roll option does have an issue in MT with too many (), but that doesn't seem to be the issue here. ie if((1)) is okay, but if(((1))) would error.

edit: I do notice in the first call with macro() you pass it a value of 1, but in the UDF call you don't pass any values. Perhaps if(canReact(1)) is your solution.


Arsil PS

unread,
Nov 24, 2018, 4:27:58 AM11/24/18
to idle_...@googlegroups.com
Hey, thanks for offering to help. That argument is unused (you have to put something after ":" or it throws an error) and yes, the called macro only returns 0 or 1.

I found weird that I had to explicitly use "==1" since I can call other UDFs omitting that, with the presumption that it is implied equals true or 1.

Anyway, it's all good. The real problem was (I think) putting a call to a macro that prints output as a condition in a "if" roll.
EDIT: nope, even if I call it like this I get no output (except 0 or 1, of course, because I'm assigning the return value to a variable, I was afraid using "h:" could hide the output from the macro):
[result=canReact()]
[if(result==1),Code:

{        
   
[h:state.ReactionUsed=1]
   
Defensive Duelist FEAT: [r:token.name] uses a reaction vs a melee attack getting a +<b>[Proficiency]</b> bonus to AC for that attack.
}]

To me the case is closed (this was really just a curiosity, I'm more concerned with the other issues), but if anyone is curious:

canReactMacro in a lib token
[h:l_canReact = 1]

[if(l_canReact==1 && state.Dead==1),Code:
{
   
[h:l_canReact=0]
   
Can&#39;t use reaction: DEAD.
}]

[if(l_canReact==1 && state.Incapacitated==1),Code:
{
   
[h:l_canReact=0]
   
Can&#39;t use reaction: Incapacitated.
}]
[if(l_canReact==1 && state.Paralyzed==1),Code:
{
   
[h:l_canReact=0]
   
Can&#39;t use reaction: Paralyzed (Incapacitated).
}]
[if(l_canReact==1 && state.Petrified==1),Code:
{
   
Can&#39;t use reaction: Petrified (Incapacitated).
   
[h:l_canReact=0]
}]
[if(l_canReact==1 && state.Stunned==1),Code:
{
   
[h:l_canReact=0]
   
Can&#39;t use reaction: Stunned (Incapacitated).
}]
[if(l_canReact==1 && state.Unconscious==1),Code:
{
   
[h:l_canReact=0]
   
Can&#39;t use reaction: Unconscious (Incapacitated).
}]
[if(l_canReact==1 && state.Slowed==1),Code:
{
   
[h:l_canReact=0]
   
Can&#39;t use reaction: Slow spell.
}]

[if(l_canReact==1 && state.ReactionUsed==1),Code:
{
   
[h:l_canReact=0]
   
Can&#39;t use reaction: already used this round.
}]

[h: macro.return = l_canReact]

UDF definition in OnCampaignLoad macro in a lib token:
[h: macro.define("isDarkenMacroButton", "isDarkenMacroButton@Lib:MacroHelper")] <!-- probably not a great idea to use the same name, but it works -->
[h: macro.define("canReact", "canReactMacro@Lib:MacroHelper")]
I also tried setting the third parameter, ignoreOutout, to 0 or 1 to check if the default value of 0 is correctly assigned when omitting it.

At last, here isDarkendMacroButton, defined in a lib token:
[h: myProps=macro.properties(macro.index())]
[h: currentButtonColor=getStrProp(myProps, "color")]    
[h: macro.return = if(currentButtonColor=="gray", 1, 0)]
this one prints no output and I can call the UDF like this (i.e. without ==true or ==1):
[if(isDarkenMacroButton()), Code:
{
 
You will regain this feature after a long rest.
};
{
 
[h:darkenMacroButton()] <!-- another UDF that calls a macro to set the BG color of the macro button to a certain color checked by isDarkenMacroButton -->
 
You do this and that.
}]
Note that these macros don't work in the current version (1.17.0) because you can't change a macro button's color or fontcolor via macro.


Reply all
Reply to author
Forward
0 new messages