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

Call macros from a dropdown...

Hello! Let's say I use this simple macro (which works): @{Selected|weapon1attackmacro} Now, say I have 10 different attack types, I could have 10 macros like the one above, but just change the 1 for the appropriate number. This would give ten macros, and ten buttons to call them during game time. I do not want to clutter my macro bar with 10 macros. So I'm trying to get all of them within one macro. I tried: @{selected|?{Choose Attack|Long Sword,weapon1attack|Short Sword,weapon2attack|Long Bow,weapon3attack}macro} That didn't work. The dropdown is displayed, but the macro isn't called, it is displayed as text instead. So I tried: ?{Choose Attack|Long Sword,weapon1attack|Short Sword,weapon2attack|Long Bow,weapon3attack} @{selected|?{Choose Attack}macro} Not working either, basically same result. I tried replacing commas, pipe characters and/or curly braces with HTML equivalents, that didn't help. I think I'm missing something obvious... Or is this type of construction not possible? Thanks for any help.
1678155196

Edited 1688493671
GiGs
Pro
Sheet Author
API Scripter
You are trying to break up the macro name into parts, which does not work. You have to keep the macro name complete. You cant put queries inside attribute calls because of the Roll20 order of operations woks. It performs all attribute and macro calls first, and then calls queries.  So when you do this @{selected|?{Choose Attack|Long Sword,weapon1attack|Short Sword,weapon2attack|Long Bow,weapon3attack}macro} It tries to call an attribute with exactly that name, which doesn't exist. You have to put your attribute calls inside the query, like ?{Choose Attack| Long Sword,@{selected|weapon1attackmacro}| Short Sword,@{selected|weapon2attackmacro}| Long Bow,@{selected|weapon3attackmacro} } But that will only work for the simplest macros for another reason. When you run a macro that calls other macros, Roll20 calls the text of those macros, places them in the first macro, then runs the macro. So if your macro was simply say .roll 1d20+a number, the above would become ?{Choose Attack| Long Sword,/roll 1d20+7| Short Sword,/roll 1d20+7| Long Bow,/roll 1d20+7} then the macro runs. But if the nested macros contain any characters that are also used by the top macro, like | or commas or }, they will be interpreted as part of the top macro, and that macro will break. You then have to change those characters to HTML entities, It's better in this case to use chat menus. They require no change to the code. Since you are using attribute syntax, it looks a lot more complicated that it would if you were using character abilities. A single chat menu button owuld looke like [Weapon1](!
@{selected|weapon1attackmacro}) To break it down, this is: [BUTTON LABEL](!
@{selected|ATTRIBUTE NAME}) you just need to change the all caps. So that looks like: &{template:default} {{name=Weapon Attacks}} {{ [Weapon1](!
@{selected|weapon1attackmacro}) [Weapon2](!
@{selected|weapon2attackmacro}) [Weapon3](!
@{selected|weapon3attackmacro}) }} If you were using character abilities instead of attributes, it would look much simpler: &{template:default} {{name=Weapon Attacks}} {{ [Weapon1](~selected|weapon1attackmacro) [Weapon2](~selected|weapon2attackmacro) [Weapon3](~selected|weapon3attackmacro) }}
1678158275
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Obligatory link:  Chat Menu
1678195053

Edited 1678250143
timmaugh
Forum Champion
API Scripter
Also, it should be mentioned that Fetch can help here, too. Specifically because of the problem GiGs notes about the expanded macro having query-breaking characters (right brace, pipe, comma). Using Roll20 syntax, all of the macros, abilities, and attributes will be expanded into the command line before the query is evaluated... so if any of them have a breaking character, your query will no longer function. On the flip side, you could build your component macros with HTML replacement characters, but then they will no longer work if you click on them, directly. Fetch works because the Fetch construction works during the metascript phase ... after Roll20 parsers have expanded macros, abilities, and attributes, handled inline rolls, and processed queries. Fetch constructions don't trip any Roll20 parsing, so when  your query would come around you're still picking from among Fetch constructions to include in the command line. It's only after the roll query has finished (and the rest of the Roll20 parsing) that Fetch gets a look at the command line. By that point, you've selected one of the macros to keep in the command line, and Fetch goes to get it for you. Even if that macro/ability/attribute has query-breaking characters in it, they no longer matter because you're getting it after the query processing has finished. This also means that now you can click on the "nested" macro and it will still work. It works in both places*. * with one caveat, see below. An example would be: ! ?{Choose Attack| Long Sword,@(selected.weapon1attackmacro)| Short Sword,@(selected.weapon2attackmacro)| Long Bow,@(selected.weapon3attackmacro)} Caveat Notice that the line begins with a bang ("!"). That gets the metascripts involved. This message now won't hit the chat output on its own. This is fine if you choose an attribute that actually invokes a script. The message will continue out of the metascripts and be caught by the script you intend to catch it. If, instead, your chosen attribute would send a simple message (like a roll template, or just text), then you'll need one more component: ZeroFrame. Using ZeroFrame, you can add a {&simple} in the query options where you need it. For example, if your weapon1 AND weapon2 attackmacro attributes sent normal text, but your weapon3 sent a script/mod command, you could add {&simple} like this: ! ?{Choose A ttack| Long Sword,@(selected|weapon1attackmacro) {&simple}| Short Sword,@(selected|weapon2attackmacro) {&simple}| Long Bow,@( selected|weapon3attackmacro)} Again, we'd add it here because we don't need it in weapon1 and weapon2... they are still unchanged, and able to be run independently of using this solution. We only add it to the options that require the "simple" output (going to chat).
Thanks everyone, it is now easier to understand why it wasn't working. I read up on the order of operations but it will take a while to fully wrap my head around all those steps... I will install Fetch in our game and test that, I want to keep the option that the macros I call could still work as stand-alone.
Jean-Guy said: I will install Fetch in our game and test that, I want to keep the option that the macros I call could still work as stand-alone. FYI that Mod scripts (such as Fetch) require the game creator to have a Roll20 Pro subscription, as I don’t see a Pro tag next to your name. 
1678238964

Edited 1678239035
Gauss
Forum Champion
Jean-Guy, Gigs and Keithcurtis mentioned chat menus but you might not have seen it.  Chat Menus avoid the problems of nesting macros into a query. Few or no HTML entities required.  If your campaign owner does not have a Pro account I would suggest going the Chat Menu route.
1678243050

Edited 1678243138
Hi Gauss & Jarren, Yes, thanks, I saw the chat menu suggestion. I'm already using chat menus for other things (and yes, we are on a Pro subscription, so we also have mods and various other scripts). But I'd like the possibility to call one of a dozen or more macros, like various attacks (one handed, two handed, single attack, full attack, range, bludgeon, special, etc; or skill saves, etc.) We are using the 3.5 sheet template and I haven't seen a lot of options to make the chat menu look nice (I think we are stuck with the default template). Those pinkish button take a lot of real estate and if I have more than say, 8 of them (2 per row on 4 rows) than it starts to look gaudy.
We installed Fetch and I tried Tim's example: !?{Choose Attack| Bastard Sword,@(selected|weapon3fullattackmacro)| Mace,@(selected|weapon5fullattackmacro)| Dragon Lance,@(selected|weapon8fullattackmacro)} But the dropdown choices went a little crazy, it was giving me "Bastard Sword" as the first item, as expected, but the second item was "weapon3fullattackmacro)". So I replaced the pipe character after "selected" with an HTML equivalent: !?{Choose Skill| Bastard Sword,@(selected|weapon3fullattackmacro)| Mace,@(selected|weapon5fullattackmacro)| Dragon Lance,@(selected|weapon8fullattackmacro)} Then the dropdown displayed the correct 3 items. But nothing happened when I made my selection and hit "Submit". No error messages or anything I could see that happened.
1678246135

Edited 1688493706
GiGs
Pro
Sheet Author
API Scripter
If you're looking for a way to present a set of macros/abilities/attributes, might I suggest my own script: <a href="https://app.roll20.net/forum/post/7474530/script-call-for-testers-universal-chat-menus/?pagenum=1" rel="nofollow">https://app.roll20.net/forum/post/7474530/script-call-for-testers-universal-chat-menus/?pagenum=1</a> I really do need to upgrade that to handle different style buttons (among other things, like improving the code).
1678247636

Edited 1678247656
Gauss
Forum Champion
Jean-Guy said: Hi Gauss &amp; Jarren, Yes, thanks, I saw the chat menu suggestion. I'm already using chat menus for other things (and yes, we are on a Pro subscription, so we also have mods and various other scripts). But I'd like the possibility to call one of a dozen or more macros, like various attacks (one handed, two handed, single attack, full attack, range, bludgeon, special, etc; or skill saves, etc.) We are using the 3.5 sheet template and I haven't seen a lot of options to make the chat menu look nice (I think we are stuck with the default template). Those pinkish button take a lot of real estate and if I have more than say, 8 of them (2 per row on 4 rows) than it starts to look gaudy. So a couple things 1) You can whisper Chat Menus to yourself so other people do not need to see them.&nbsp; 2) I just wrote a guide on how to reformat chat menus to get rid of the pink button. It should be easy to follow. If you have any questions feel free to ask me.
1678250293
timmaugh
Forum Champion
API Scripter
Jean-Guy said: We installed Fetch and I tried Tim's example: !?{Choose Attack| Bastard Sword,@(selected|weapon3fullattackmacro)| Mace,@(selected|weapon5fullattackmacro)| Dragon Lance,@(selected|weapon8fullattackmacro)} But the dropdown choices went a little crazy, it was giving me "Bastard Sword" as the first item, as expected, but the second item was "weapon3fullattackmacro)". So I replaced the pipe character after "selected" with an HTML equivalent: !?{Choose Skill| Bastard Sword,@(selected&amp;#124;weapon3fullattackmacro)| Mace,@(selected&amp;#124;weapon5fullattackmacro)| Dragon Lance,@(selected&amp;#124;weapon8fullattackmacro)} Then the dropdown displayed the correct 3 items. But nothing happened when I made my selection and hit "Submit". No error messages or anything I could see that happened. And *that* is why Fetch supports both pipes and periods as the separator character for the fetched item: Fetch runs *after* Roll20 parsing (including roll queries), so you have to use the period version of the Fetch formation if you want to use it in a roll query. I fixed my example, above, and I'll include it here, too: !?{Choose Attack| Bastard Sword,@(selected.weapon3fullattackmacro)| Mace,@(selected.weapon5fullattackmacro)| Dragon Lance,@(selected.weapon8fullattackmacro)} That should work better for you.
Hello Tim, I tried with periods instead of pipes (or their HTML version). The dropdown displayed correctly, but again, no visible reaction at all. I tried with macro names I know don't exist, still no reaction. So it seems that the script is not even reaching the stage where it should evaluate the macro name and execute it. Is there a way I can trace (or debug) the macro? Or, is there an order to install the scripts? Here are all the scripts we load: ChatSetAttr Libliline APILogic GroupInitiative SelectManager Messenger TokenMod Vector Math MatrixMath Path Math checkLightLevel libTokenMarkers Fetch Thanks!
Hello Gauss, So a couple things 1) You can whisper Chat Menus to yourself so other people do not need to see them.&nbsp; 2) I just wrote a guide on how to reformat chat menus to get rid of the pink button. It should be easy to follow. Thanks for the tips. I already send most of my chat menu to myself with whisper. But if I have too many rows, it won't look nice. So your information about formatting the command buttons really helps. I can look up the various values those parameters can take and I'll create something a lot better. Do you know if we can also reformat the left side of the basic two column chat menu, or, what I mean is can we format an element that doesn't have the basic [command name](~ability-name) format? Can we set a font for the whole chat menu, or is it just the command buttons we can manipulate? For instance, say a first row in my chat menu is something like: {{Bless:=[On](~Réjean|BlessON" style="border:none;background-color:transparent;padding:0px;color:#3bb86c;font-weight:bold;) [Off](~Réjean|BlessOFF" style="border:none;background-color:transparent;padding:0px;color:#ee9112;font-weight:bold;)}} WIth your help, I was able to format my "ON" and "OFF" buttons, but can I format the "Bless:" part as well? Thanks for the help!
1678333817
timmaugh
Forum Champion
API Scripter
Jean-Guy said: Is there a way I can trace (or debug) the macro? Or, is there an order to install the scripts? Yes... there is. BTW, I think the problem you're running into is having fetched macros that should be simple messages, and needing to get them output. The good news is that logging the message should tell us. To log the message, install ZeroFrame and then add this to the end of your command line (at the end is fine): {&amp;log} The log panel will hit the chat. You should see Fetch expanding the sheet item during the first loop. You can also see (in the Outro section at the bottom) what the final state of the command line is. Share a copy/paste or screenshot of that, and we can probably say for sure what the issue is&nbsp;
1678340394

Edited 1678340441
timmaugh said: Jean-Guy said: Is there a way I can trace (or debug) the macro? Or, is there an order to install the scripts? Yes... there is. Ok, I'm not sure if your "yes" is about the tracing or the order to load the scripts we use. Reading your answer confirms that I can trace the macro by looking at an output log in the chat menu. But I need to load yet another script. Before I load ZeroFrame, can you tell me if our scripts are loaded in the correct order, and where in that sequence should we load ZeroFrame? Here are our scripts: ChatSetAttr Libliline APILogic GroupInitiative SelectManager Messenger TokenMod Vector Math MatrixMath Path Math checkLightLevel libTokenMarkers Fetch Thanks!
1678362631
timmaugh
Forum Champion
API Scripter
Sorry, Jean-Guy... I meant to say that installing ZeroFrame makes it BOTH so that you can log the message AND that you don't have to worry about the order scripts load. With it installed, the rest of the metascripts will run in the order ZeroFrame dictates. You can change the order they run without changing your installation order... You can change it as a matter of global configuration or as an ad hoc order for just a single message, but for our purposes the default order will be fine.
1678382892

Edited 1678383041
Gauss
Forum Champion
Jean-Guy said: Hello Gauss, So a couple things 1) You can whisper Chat Menus to yourself so other people do not need to see them.&nbsp; 2) I just wrote a guide on how to reformat chat menus to get rid of the pink button. It should be easy to follow. Thanks for the tips. I already send most of my chat menu to myself with whisper. But if I have too many rows, it won't look nice. So your information about formatting the command buttons really helps. I can look up the various values those parameters can take and I'll create something a lot better. Do you know if we can also reformat the left side of the basic two column chat menu, or, what I mean is can we format an element that doesn't have the basic [command name](~ability-name) format? Can we set a font for the whole chat menu, or is it just the command buttons we can manipulate? For instance, say a first row in my chat menu is something like: {{Bless:=[On](~Réjean|BlessON" style="border:none;background-color:transparent;padding:0px;color:#3bb86c;font-weight:bold;) [Off](~Réjean|BlessOFF" style="border:none;background-color:transparent;padding:0px;color:#ee9112;font-weight:bold;)}} WIth your help, I was able to format my "ON" and "OFF" buttons, but can I format the "Bless:" part as well? Thanks for the help! My guide was intended as a guide for folks to convert the basics easily, without having to learn much about what they are doing.&nbsp; The original basis of this can be found HERE . For more complicated stuff I suggest asking Oosh as he is the original author of that.&nbsp; Also, what is the entire macro? It may make a difference. (Such as which template you are using)
Gauss said: Also, what is the entire macro? It may make a difference. (Such as which template you are using) We're using the 3.5e template, so for chat menu I believe that we can only use the "default" temple, correct? I think that the "npcaction" template is for the 5e template, right? Thanks, I'll look up CSS and the info Oosh posted, I quickly diagonally read that post you linked to a few days ago. Once I settle my other issue with activating macros from a dropdown, I'll look at it more attentively. Cheers!
timmaugh said: for our purposes the default order will be fine. Cool, if I understand correctly, once ZeroFrame is installed (regardless of loading order) it will take care of the other meta scripts using a default order that, if needed down the line for specific issues, we could modify. We'll install ZeroFrame and I'll test again the basic macro you suggested. If it doesn't work I'll generate the log and copy/paste it back here. My GM is interested in having this idea work because he says he has several macros and it would be easier for him to categorize them using a few drop downs instead of having buttons all over the place or using chat menus... Thanks a lot!
Hello Tim, We installed ZeroFrame , but we must have done something wrong. Regular basic 3.5e sheet macros still work, but none of the macros that involve a script (like ChatSetAttr ) work anymore. Even the great Fish Lobbing "If" example you gave me doesn't work anymore. For example, heres's a simple macro that doesn't work: &amp;{template:default} {{name=**HP Modification**}} !modattr --silent --charid @{selected|character_id} --hitpoints|?{HP (Plus or Minus)|0} !!! {{Result=Modify HP value for @{selected|character_name} by ?{HP (Plus or Minus)}.}} The macro kinda works though (for example, in the example I pasted above, the Pop Up appears and asks the question about HP [ HP (Plus or Minus) ], but it doesn't apply it to the selected character and doesn't generate an error message. Also, {&amp;log} doesn't generate anything I can see in the chat menu, so I think that ZeroFrame is doing something to the other scripts. Thanks!
1678515585
timmaugh
Forum Champion
API Scripter
It sounds like you have a script problem. There are a couple of ways scripts can quietly break... for instance even just having a blank line between scripts (so scripters have to make sure they add that to their code). If you enter this command into chat with ZeroFrame installed: !0 You should get an output like this: If you don't get something like that (with the metascripts you have installed), then you're likely dealing with one of these issues. If you (or your GM) want to invite me/promote me I can try to jump in and take a look.
timmaugh said: It sounds like you have a script problem. Probably, and it seems it is related to ZeroFrame . My GM created a Test Game where I'm the GM, since he has the Pro subscription, the game he created also has the Pro level. So I went ahead and installed all the same scripts in the same order that we have in our main game. Then I tested the APILogic sample you gave me about this Fish Lobbing Artist, hence forth called the "Fish Test", Everything worked as advertised, So I closed the game, installed ZeroFrame and saw the following in the Mod Output Console : Then I restarted the game. Before doing any macro ZeroFrame related I tested !0 from the chat menu. Here's the output: Then I tested the Fish Test with {&amp;log} appended at the end, and here's the output: So up to that point everything was still working as expected. Then I tested the macro you suggested to accomplish what initiated all this, i.e. a macro that displays a dropdown that will excute a macro based on the item selected. Here's the macro: !?{Choose Attack| Bastard Sword,@(selected.weapon2fullattackmacro)| Mace,@(selected.weapon7fullattackmacro)| Dragon Lance,@(selected.weapon3fullattackmacro)}{&amp;log} I was able to select one of the three attacks from the expected displayed dropdown list, but after that no output at all, no log, no errors. So I closed the game and saw the following when I went to remove ZeroFrame : So I removed ZeroFrame and everything went back to working normally. If you still want, I can invite you to that test game. but I'm not sure how to do that... I mean I see how to invite players, but I do not see the option to give an invited player the GM status. Can only the game creator do that? Thanks for your time!
1678678725
timmaugh
Forum Champion
API Scripter
So, that kind of error typically crops up with a bad roll construction... which would be in the way the command line is structured of whatever macro you're running out of that roll query. There are certain quirks of building inline rolls that work for player-generated rolls but do not for script-generated rolls (silly things like a leading space after the opening double brackets). With the sandbox broken, you won't get a ZeroFrame log output... and when you remove ZeroFrame that will reboot the sandbox and things will work again. Go ahead and invite me. As a GM, you should be able to promote me once I'm in. I'll take a look at your setup and see if I can spot anything.