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

Grouped Drop-down of nested Macros for Selected Token

Hi all, I am trying to make four working macros (titled NPC, Spells, Saves, and Feats) that each work on their own into a drop-down menu. However, I get the error that no token is selected once combined that I don't get if calling the individual macros. Here is my text, and thanks in advance for any help: ?{NPC |    Full,!NPC |    Spells,!Spells |    Saves,!Saves |    Feats,!Feats | }
What are the contents of !NPC, !Spells … etc.? I’m guessing those script calls have an @{selected call. Or is there  more to your initial macro?
Yes, and they use ChatMenu Here's "Saves" for example: !chatmenu @{selected|character_id} {template:pc}{{charname=@{selected|character_name}}} {{type=}} {{smallname=Defenses}} {{showchar=[1]}} {{descflag=1}} {{desc=CHATMENU **Defense Statistics** AC @{selected|ac} |Touch @{selected|ac_touch} |Flat-Footed @{selected|ac_flatfooted} |CMD @{selected|cmd_mod} |SR @{selected|sr} }} {{shownotes=[1]}} {{notes=**- Fort:**@{selected|fortitude_notes} |**Ref:**@{selected|reflex_notes} |**Will:**@{selected|will_notes} |**AC:**@{selected|ac_notes} |**CMD:**@{selected|cmd_notes} |**SR:**@{selected|sr_notes}}} --separator:~ --title:Stats --STR(@{selected|strength}),strength|DEX(@{selected|dexterity}),dexterity|CON(@{selected|constitution}),constitution|INT(@{selected|intelligence}),intelligence|WIS(@{selected|wisdom}),wisdom|CHA(@{selected|charisma}),charisma --title:Saves --Fort(@{selected|fortitude}),fortitude --Ref(@{selected|reflex}),reflex --Will(@{selected|will}),will 
As soon as !Saves is called (when you select it from the query), there is the @{selected reference, so Roll20 needs a token to be selected in order to get the information that is being called for. 
But this failure occurs when a token is selected.
1715288687
GiGs
Pro
Sheet Author
API Scripter
That sounds familiar. Isn't that just the classic Roll20 order of operations and "nested queries require html entities" problem? When you run a roll20 macro, it first "expands" every macro (replacing the macro name with the contents of that query), then it attempts to replace all attribites, abilities and the like with their contents, then it completes the query. This means that any calls like @{selected|ac_notes} will be replaced by their contents (and if they contain any special query characters, like "," the query will end prematurely) any characters like } and | and , will prematurely end the query. (note this occurs aftert the expansion of attribute calls) Is this what's going on here? If so, you'd be better off putting those maro calls (!npc, !spells, etc) in a chat menu of their own.
1715288796
GiGs
Pro
Sheet Author
API Scripter
By the way, in this ?{NPC |    Full,!NPC |    Spells,!Spells |    Saves,!Saves |    Feats,!Feats | } you don't need the final | (that's called a pipe). The pipe basically tells the query, "start a new line here" and you don't need that on the last line, so it should be ?{NPC |    Full,!NPC |    Spells,!Spells |    Saves,!Saves |    Feats,!Feats}
1715289148
timmaugh
Forum Champion
API Scripter
Something that begins with a bang (!) is not going to be a macro... That is, it is not going to be expanded as a roll20-retrievable thing. Statements that begin with an exclamation point are messages that skip the chat output, and are only sent to the script moderator.  If you have a script which is using those handles (like "!NPC") to then turn around and launch the chatmenu command, then what you have is a script calling another script. In that case, you have to imagine that it is the script moderator itself, the sandbox, acting as the calling player. The script moderator does not have any token selected, so when that command goes through the chatmenu command will never see selected tokens. If that accurately describes your situation, then you need SelectManager installed. You get it by installing the MetaScriptToolbox. SelectManager keeps track of selected tokens and gives them back to a downstream message when a script calls a script, so just by installing it you should be able to take care of this problem.  FYI, there are 2 other properties of the message object that change when a script initiates the message versus when a player does. SelectManager can give both of those properties back to the message as well, but it does not come pre-configured to do so. This is because some rare scripts do need to know who initiated the message, so I left it up to the individual game owner to enable or disable these functions of SM. This case is rare enough that I have only ever seen one situation where it mattered in the many years since I wrote selectmanager, so you're probably okay to go ahead and configure it to give those other two properties back.  To do that, run this command one time after the toolbox is installed:  !smconfig +who +playerid If all of this does not solve your problem, then please post back with more details about your actual setup, because what you are saying does not match the example text you have provided.
1715289510
timmaugh
Forum Champion
API Scripter
GiGs said: That sounds familiar. Isn't that just the classic Roll20 order of operations and "nested queries require html entities" problem? When you run a roll20 macro, it first "expands" every macro (replacing the macro name with the contents of that query), then it attempts to replace all attribites, abilities and the like with their contents, then it completes the query. This means that any calls like @{selected|ac_notes} will be replaced by their contents (and if they contain any special query characters, like "," the query will end prematurely) any characters like } and | and , will prematurely end the query. (note this occurs aftert the expansion of attribute calls) Is this what's going on here? If so, you'd be better off putting those maro calls (!npc, !spells, etc) in a chat menu of their own. If these were truly macros, preceded by the hash character (#), then the order of operations  would come into play, except that it should go abilities, macros, attributes, and that loop should proceed up to 99 times. So even if these were macros, it should expand the first time, then catch the references to selected the next time. But, if we take the supplied text as exactly what is executed, these are not macros. These are API statements.
1715293003
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
What timmaugh said. If you have a macro called "!Saves", it needs to be sent to chat as "#!Saves". "!Saves" just gets swallowed by the text parser unless a script has been built to intercept it.
1715293926
GiGs
Pro
Sheet Author
API Scripter
oh yes, I already knew they were macros so I didn't pay the attention I should have to the ! at the start of the name.
1715298603
timmaugh
Forum Champion
API Scripter
keithcurtis said: What timmaugh said. If you have a macro called "!Saves", it needs to be sent to chat as "#!Saves". "!Saves" just gets swallowed by the text parser unless a script has been built to intercept it. That does lead to a simpler explanation... Ao, if your macros are named "NPC", "Spells", "Saves", and "Feats", then in order to reference them, you'd use a hash, not a bang. Also, if there is any text before them in the command line, the hash must have a space preceding it (including in your query). If that's the situation, then when you correct your macro references, you're going to break your query (because of the order of operations expanding the macro text into the query before the query is parsed. At that point you have 3 options... HTML substitutions (not a good solution, for many reasons) Metascripts Chat Menus Most people choose chat menus, but the metascript option can be simple, too. At this point, though, you might just need to explain the actual state of things better, then we can give you better advice. =D
Thanks all, I figured it out well enough with Chat Menus