Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Calling a Macro from a Query

December 04 (6 years ago)

I am trying to put together some macros for a old school MSH game. It has 18 individual Attack Feats which I wanted to place within a queery, so the player could select which one they wish to do from a list. The macro's themselves work without issue, but when I try to execute from a queery it will not work.

Here is an example of the queery and the embedded macros.

Battle-FEATs

?{Attack FEAT | Blunt Attacks, #BA | Edged Attacks, #EA }

BA

&{template:default} {{name=Blunt Attacks}} {{rank=#Rank }} {{Roll=[[1d100]]}} {{Result=White: Miss
Green: Hit
Yellow: Slam
Red: Stun}}

EA

&{template:default} {{name=Edged Attacks}} {{rank=#Rank }} {{Roll=[[1d100]]}} {{Result=White: Miss
Green: Hit
Yellow: Stun
Red: Kill}}

Ranks

?{Attack Rank | Fb, #Feeble | Pr, #Poor | Ty, #Typical | Gd, #Good | Ex, #Excellent | Rm, #Remarkable | In, #Incredible | Am, #Amazing | Mn, #Monstrous | Un, #Unearthly | ShX, #Shift-X | ShY, #Shift-Y | ShZ, #Shift-Z | Class 1000, #Class-1000 | Class 3000, #Class-3000 | Class 5000, #Class-5000 | Beyond, #Beyond }


December 05 (6 years ago)

So, if the individual macros work fine when called directly, but not when called from your other macro, you, like so many before you, have run into the character substitution problem that plagues the use of queries - basically, the called macros, or sub macros, are pre-parsed into the top level macro, then the top level macro is parsed as one giant macro with all the sub macros already parsed into it.  However, part of this process strips out certain characters.


You can either write the sub macros using character substitutions such that this pre-parse actually assembles them into the right syntax, or better, is you can replace the top level macro with a "Chat Menu", which is described in the stupid tricks forum post.  I find the chat menu to be far easier to write and debug, so I encourage you to look into it.

December 05 (6 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Just to make it easier, the Chat Menu post is here in the Stupid Tricks thread.

December 08 (6 years ago)

If I understand this correctly, this should give me a chat menu named FEATs Menu and have a single selection of Blunt Weapons.

/w gm &{template:5e-shaped} {{title=FEAT Menu}} {{text_big=[Configure Shaped Options](!shaped-config)
**Ability FEATs**
[Blunt Attack](#BA)
}}

Which did not work, all I got was a yellow GM whisper window with nothing in it. I also tried [Blunt Attack](!
#BA) and [Blunt Attack](~BA) with the same result.

The Blunt Attack macro is and works fine if not used in conjunction with anything else:

&{template:default} {{name=Blunt Attacks}} {{rank=#Rank }} {{Roll=[[1d100]]}} {{Result=White: Miss
Green: Hit
Yellow: Slam
Red: Stun}}


The Rank macro is:

?{Attack Rank | Fb, #Feeble | Pr, #Poor | Ty, #Typical | Gd, #Good | Ex, #Excellent | Rm, #Remarkable | In, #Incredible | Am, #Amazing | Mn, #Monstrous | Un, #Unearthly | ShX, #Shift-X | ShY, #Shift-Y | ShZ, #Shift-Z | Class 1000, #Class-1000 | Class 3000, #Class-3000 | Class 5000, #Class-5000 | Beyond, #Beyond }

December 08 (6 years ago)

Edited December 08 (6 years ago)

I got this macro to work up to a point. It does not call the #BA macro, but does call the #Rank macro. So odd.

&{template:default} {{name=?{Battle FEAT to use?|Blunt Weapons,#BA} FEAT check}} {{rank=#Rank }} {{Roll=[[1d100]]}}

Further update, I have tried replacing the # symbol with # as well as replacing the , symbol with , and it still does not work. This is the output:


December 08 (6 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

I believe the reason the Rank macro works, but the Blunt does not is that Blunt is causing you to embed one roll template within another. It can be done, but is beyond my abilities. I've always needed assistance to work that out. It's deep Macro Voodoo.

December 08 (6 years ago)

Yeah I know, the really odd thing is the call to #BA is before the call to #Ranks. So there is something about the format inside the queery when it calls a macro.

December 08 (6 years ago)
GiGs
Pro
Sheet Author
API Scripter

Macros aren't processed on the order they are listed. They are processed all at once. The first thing that happens, is that the parser looks at the linked macros (BA and Ranks), and replaces the call (#BA) with the actual text in that macro. Only when all those replacements have been done, does the parser try to run full macro.

At that point, the nested roll templates exist, and you run into the nested characters problem.

Generally the advice for things like this, is to NOT use nested macro calls, but to copy the text from the nested macro into the base macro, and then work on how to deal with the html entities. It's a pain.

December 08 (6 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

The order should not matter. Putting a template inside a template, even as a macro call is very tricky.