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

Mt is undefined result while using a Macro Caller

December 11 (1 year ago)
Lucky
Plus

I'm trying to write an ability that asks a question and, depending on the answer, will print a table of button options to the chat box.

It does all that ... but when I press any of the macro buttons it returns the "TypeError: Mt is undefined" error.

I have the following abilities:

  • !Perception
  • !Stealth
  • !Ki-Poison

(The "Does not exist" macro ... doesn't exist, it's just a placeholder for the future.)


And the macro caller code is:

/w Lucky &{template:default}  {{name=Macro Options
}} {{?{Type
|Options, **Options Header**
[Perception](~!Perception)
[Stealth](~!Stealth)
[Ki-Poison](~!Ki-Poison)
|Other,
[Does not exist](~Does not exist)
} }}
December 11 (1 year ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

This going to be something with your macros that are being called by the created buttons, not with this macro.

December 11 (1 year ago)

Edited December 11 (1 year ago)
Lucky
Plus

All the macros I've tried (when being called as a result of the query) have the same "TypeError: Mt is undefined" error.

Without the query, they all work.


Here is the code of those specific queries:

!Perception

&{template:default} {{name= Perception Actions}}  {{Perception = [[ 1d20 +@{Perception} ]] }} {{Notes=@{Perception_Notes} }}{{Swift Action %NEWLINE% DC 20 = [Clarity of Vision](https://dnd.arkalseif.info/feats/complete-scoundrel--60/clarity-vision--3278/index.html) %NEWLINE% Pinpoint location of invisible creatures within 30 ft until end of turn}} {{Standard Action %NEWLINE% DC is the AC of target = [Spot the Weak Point](https://dnd.arkalseif.info/feats/complete-scoundrel--60/spot-weak-point--3307/index.html) %NEWLINE% Next attack against that opponent (which must be no later than next turn) is treated as touch attack. %NEWLINE% If you use a ranged weapon to deliver the attack, opponent must be within 30 ft of you to benefit from this skill trick.}}

!Stealth

&{template:default}  {{name= Stealth Actions}}  ?{Stealth Type| Mundane Stealth, {{**Mundane Stealth** %NEWLINE% [Darkstalker](https://dnd.arkalseif.info/feats/lords-of-madness--72/darkstalker--512/index.html) = [x](https://i.stack.imgur.com/l7cbW.jpg) %NEWLINE% [[ 1d20 +@{Stealth} ]] %NEWLINE% (Immune to blindsense, blindsight, scent, and tremorsense) | Invisibile, {{[Invisible](https://www.d20pfsrd.com/gamemastering/conditions/) %NEWLINE% [Darkstalker](https://dnd.arkalseif.info/feats/lords-of-madness--72/darkstalker--512/index.html) %NEWLINE% [Invisible Blade](https://www.d20pfsrd.com/classes/alternate-classes/ninja/ninja-tricks/paizo-ninja-master-tricks/invisible-blade/) %NEWLINE% [Headband of Sealed Thoughts](https://www.d20pfsrd.com/alternative-rule-systems/mythic/mythic-magic-items/other-magic-items/) = [x](https://31.media.tumblr.com/6722f3c6efedf6cfcdae0e749f562efb/tumblr_ne9x5heiXI1t5gphro1_500.gif) %NEWLINE% [[ 1d20 +@{Stealth} +20 ]] %NEWLINE% +20 When Stationary  %NEWLINE% (Immune to blindsense, blindsight, scent, and tremorsense) %NEWLINE% (Cannot be detected through Divination magic) } }} {{note=@{Stealth_Notes} }} 

!Ki-Poison

&{template:default}  {{name=Ki Poison}}  {{Damage=Poison (Injury) %NEWLINE% Apply w/ Swift Action %NEWLINE% [[1d6]] Ability Damage %NEWLINE% (Choose Str, Dex, Con or Wis)}}  {{Note= Negate: Fort DC [[10 +(12/2)[Ninja Level] +@{cha_mod}]] %NEWLINE% 1/round for 3 rounds.}} {{Usage=Once per day, but can regain a use by spending 2 Ki Points.}}


December 11 (1 year ago)

Edited December 11 (1 year ago)
GiGs
Pro
Sheet Author
API Scripter

I'd pick one of your macros, make a copy of it, and the in the copy start removing bits sequentially and see when that error vanishes. (Or remove everything and add things back in one step at a time.)

"TypeError: Mt is undefined" appears when you click an ability button that doesn't have a character attached. This happens if you typed [Perception](~!Perception) or similar directly into the chatbox.


When editing an ability the Roll/"Test Ability" button it doesn't roll it as an ability but tests it almost as if you typed it all into the chatbox. Whilst it is smart enough to ensure attributes get qualified with the character name ( So @{level} would become @{NAME|Level} ) this doesn't happen with abilities or ability buttons. So any use of these doesn't work properly with the "Test ability" button during editing.


You have to save the ability then use the normal roll button for these things to work properly. However when ability buttons get qualified with the character id it expands [Perception](~!Perception) into [Perception](~CHARACTER_ID|!Perception). This happens before the query gets handled and that " | " in the middle of the ability button will break your query.


So to get this working as intended for ability buttons inside queries you need to fully qualify and then use html escapes for both the | and ~

You can do this by replacing the ~ with

~@{character_id}|

So in all it becomes this

/w Lucky &{template:default}  {{name=Macro Options
}} {{?{Type
|Options, **Options Header**
[Perception](~@{character_id}|!Perception)
[Stealth](~@{character_id}|!Stealth)
[Ki-Poison](~@{character_id}|!Ki-Poison)
|Other,
[Does not exist](~@{character_id}|Does not exist)
} }}
December 11 (1 year ago)

Edited December 11 (1 year ago)
GiGs
Pro
Sheet Author
API Scripter

Doh! of course it was missing character names.

Why do you need to use html entities there?

The handler that manages the ability buttons (so they can be used without names) happens before queries. So when the handler adds the vertical bar it messes with the query options. So the ~ is replaced to prevent the handler adding a | but then you have to do the handlers job of providing the name/id and the escaped | to not interfere with the query. The other problem being the ability button handler doesn't fire when using the "Test ability" button

December 11 (1 year ago)
GiGs
Pro
Sheet Author
API Scripter

That makes sense, but I was sure I'd created macros like that before that didn't use html entities.Am I misremembering, or is there a way to do it?

There are ways to generate a single button based on a query since you can keep the offending syntax outside the query. Such as

[?{Skill|Perception|Stealth|etc}](~?{Skill})
[Click Me](~@{character_name}|?{Ability|Computers|Engineering|etc})

To get a list of buttons is more chat menu territory. Speaking of which...


Lucky you may want to consider using Chat Menus rather than embedding inside queries.

December 12 (1 year ago)
GiGs
Pro
Sheet Author
API Scripter

I'm probably thinking of pure chat menus without the query.

December 12 (1 year ago)
Lucky
Plus

Sorry for the delay, just now getting back to it ... Thanks, it worked!!! This was fantastic help!!!
I also appreciate the back and forth discussion as well!

I had tried HTML Replacements due to being nested within a query, but never even considered that the character name was being adding in using '~' behind the scenes (which seems obvious now) and that the generated name would require HTML Replacements!


I seem to have 1 more issue, which I'm sure is also something simple that I'm just overlooking.
No query this time.
I get the same 'Mt is undefined' error, which I believe means that the macro/ability name wasn't found ... likely due to special characters used or a typo. (Please correct me if that's not quite right!)

  1. Why is it that even though this version is not nested within a query, the 'standard' version of [button](~abilityname) doesn't work and it must still be fully qualified with html escapes? (see below example)
  2. Slighty off topic ... I noticed that not everything that has an html replacement seems to need it replaced, even within a query. (See the '-' in the ability names called in the code below) I'm guessing it has something to do with if the special character is used within whatever it is nested in.
    Example: ) , } , |(pipe) and ,(comma) are used in a query and an occurrence of one of these breaks the query early. But ( & { are not used after the initial parentheses and so it seems to ignore it. Am I on the right track? Is there a list of characters that break various bits of code?


MacroMenu Spells

/w Lucky &{template:default}  {{name=Macros for Casting Spells
}} {{**Level 0 Spells**
}} {{[Detect Magic](~@{character_id}|Lvl 0 Spell - Detect Magic)
[Detect Magic faulty](~Lvl 0 Spell - Detect Magic)
[Ghost Sound](~@{character_id}|Lvl 0 Spell - Ghost Sound)
[Ghost Sound faulty](~Lvl 0 Spell - Ghost Sound)
[Open/Close](~@{character_id}|Lvl 0 Spell - Open/Close)
[Open/Close faulty](~Lvl 0 Spell - Open/Close)
[Read Magic](~@{character_id}|Lvl 0 Spell - Read Magic)
[Read Magic faulty](~Lvl 0 Spell - Read Magic)
}} {{**Level 1 Spells**
}} {{[Expeditious Retreat](~@{character_id}|Lvl 1 Spell - Expeditious Retreat)
}}


Lvl 0 Spell - Detect Magic (as a sample of an ability being called)

?{Post|Public, |Private,/w Lucky |GM,/w GM} &{template:default} {{name=Detect Magic
}} {{Spell Level = [[0]]
}} {{School = Divination
}} {{Casting Time = Time
}} {{Components = V, S
}} {{Range = 60 ft.
}} {{Area = cone-shaped emanation
}} {{Duration = concentration, up to [[@{Level}-13]] Minutes
}} {{Saving Throw = None
}} {{Spell Resistance = No
}} {{Description
= [Detect Magic](link stripped away)
1st Round: Presence or absence of magical auras.

2nd Round: Number of different magical auras and the power of the most potent aura.

3rd Round: The strength and location of each aura. If the items or creatures bearing the auras are in line of sight, you can make Knowledge (arcana) skill checks to determine the school of magic involved in each. (Make one check per aura: DC 15 + spell level, or 15 + 1/2 caster level for a nonspell effect.) If the aura eminates from a magic item, you can attempt to identify its properties (see Spellcraft).
}}


December 12 (1 year ago)
GiGs
Pro
Sheet Author
API Scripter

You have @{character_id} in your code. But that just tells you an id of a specified character. On its own, it won't work.

I'm also wary of this part:

Lvl 1 Spell - Expeditious Retreat

Macro names should never contain spaces. Whenvyou create a new macro, any spaces in the name will be sneakily replaced by hyphens (this has caught me out a few times(. So you'll want to check if that macro actually exists.


For your question: the characters you need to watch oyt for are those used by a query after the initial {. So pipes (|), commas, and } mainly. I can't think of others off-hand.

You should never replace characters inside an attribute or ability call though.

December 12 (1 year ago)

Edited December 12 (1 year ago)
Lucky
Plus

It exists.

I'm aware of the spaces being replaced by hyphens (in awkward ways, as the replacement is made and then the insertion point jumps to the end of the name).

The way around this is to type the name of the macro/ability somewhere else (such as in the body of the macro) and copy/paste it into the name field. ;)

I've not (yet) had any issues that stem from macro name having a space in it, even when calling the macro.

December 12 (1 year ago)
GiGs
Pro
Sheet Author
API Scripter

If you use that copy trick, the macro will properly exist

December 12 (1 year ago)
Lucky
Plus

What I meant was ...
This code works:

[Detect Magic](~@{character_id}|Lvl 0 Spell - Detect Magic)

This code does not work:

[Detect Magic faulty](~Lvl 0 Spell - Detect Magic)

But it's not nested in a query, so I'm confused why it needs to be fully qualified.

December 12 (1 year ago)
GiGs
Pro
Sheet Author
API Scripter

Try putting a character name without html enties, like

[Detect Magic faulty](~Bob the Builder|Lvl 0 Spell - Detect Magic)

or the egenric selected:

[Detect Magic faulty](~selected|Lvl 0 Spell - Detect Magic)

December 13 (1 year ago)
Lucky
Plus

Odd ...

It seems that when I have the initial macro open (as if editing it) ... the version that is fully qualified functions fine, but the version that uses the '~' does not work.

However, the same macro, after clicking the checkmark to close it, will function perfectly for both buttons. This functionality remains tied to the template regardless of if the edit window is open or not after rolling it.

I think the issue is the actual method of being activated.
(Roll icon that's visible when editing does not work .. but the roll icon to left of ability as well as the button on macro bar work fine.)

... bug?



Another issue I came across (but fixed) .. was ...
One of the 'spaces' I had used as a name prefix (for several abilities) had an odd character that appeared indistinguishable from a space. (Possibly Char(160)?)

Once I deleted and rewrote the name, it worked fine. Something to think of in future troubleshooting, I guess. :)


Again, thanks for all your help!

December 13 (1 year ago)

Edited December 13 (1 year ago)
GiGs
Pro
Sheet Author
API Scripter


Lucky said:

It seems that when I have the initial macro open (as if editing it) ... the version that is fully qualified functions fine, but the version that uses the '~' does not work.

Is this a macro with any html entities? If so, you might want to look at your process. When you open a macro containing an html entity, that entity is parsed, being replaced by the character it represents and is no longer a html entity.

If this isn't your issue, I don't know what is happening, but the way you trigger the macro shouldn't have an effect. people have in the past suggested this might be an issue, but every single time that I'm aware of where this has happened 9and there have been a few times), the issue has been a html entity being parsed.

That long-standing-bug also affects %{ability} syntax whilst editing and is how your initial error happened. Since during editing abilities and ability buttons don't get qualified you either have to qualify them yourself or save it then run it, as you worked out.