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 .
×

Using a Mod Command in a Macro - What to Do If Mod uses ' --' to Prefix Arguments?

1783071399

Edited 1783100561
Solved, thank you to all. Had a space in front of the macro and a trailing ) that also messed things up. This is for an AD&D 1e campaign, though I think it is generic enough to ask the wider community. It is a macro question, but one that has to do with mods, so I figured this would be the better place to ask. I have a series of Mod commands to list spells in the chat window for a spell caster.  It starts with defining 2 variables separated by " --". The variables are character ID and the spell level: on("chat:message", function(msg) { if (msg.type === "api" && msg.content.startsWith("!picklevelspells")) { let chatcommand = msg.content.trim(); let args = chatcommand.split(/\s*--/); let charid = args[1]; //Character ID from !admin chat let specspelllevel = args[2] || ""; The spell level can be passed as strings, 0 to 9 and includes a choice of "all". If spell level is passed as a zero length string, the mod will run a roll query to choose. To start things off, a spells button is clicked on the main menu: Clicking the bottom button results in a roll query of spell levels choice of "all" and 0 to 9 or 0-7 if not a magic user (AD&D 1e). In the AD&D 1e sheet one can have three classes. The code example for magic users is: if (class1.toLowerCase() === "magic user" || class2.toLowerCase() === "magic user" || class3.toLowerCase() === "magic user") { if (specspelllevel === "") { btnspellchoice = '[First, Click to Choose Spell Level](!spells --' + charid + ' --?{Spell Level |All Spells,all|Cantrips,0|1st Level,1|2nd Level,2|3rd Level,3|4th Level,4|5th Level,5|6th Level,6|7th Level,7|8th Level,8|9thLevel,9})' ; } else { btnspellchoice = "!spells --" + charid + " --" + specspelllevel; } sendChat(strname, btnspellchoice);                  <<SNIP>> I've bolded the roll query, above. It works just fine (The selected magic user (AD&D 1e) does not have any cantrips. We actually don't use cantrips/orisons): So I'd like to put this in a token action macro, I'm wondering how to how to deal with the " --" that prefix the arguments for !picklevelspells if I were to try and put this as a macro? Plugging this into a macro; !picklevelspells --@{selected|character_id} --?{Spell Level |All Spells,all|Cantrips,0|1st Level,1|2nd Level,2|3rd Level,3|4th Level,4|5th Level,5|6th Level,6|7th Level,7}) Gives me the roll query to select all or level. But all that happens is an output to the chat tab - note that the character ID is prefixed with a sing;e dash: So I am clearly missing something in formatting the macro with !picklevelspells. Can you help? Thanks.
1783088621
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I'm not familiar at all with the script, but the macro in the code, the one that you bolded, is not the same as the one in your token action. The one from the code starts with "!spells", and the one in your action starts with "!picklevelspells". The initial code would not seem to allow for "!spells", but I only see snippets to work with.
1783090427

Edited 1783090580
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Agree with Keith. Although, I notice that picklevelspells appears in your first snippet, but it is t clear how these work together. There is another issue though; there is a leading space in the token action version, which is why it's appearing in chat; the first character isn't an exclamation point, so it isn't treated as an API message.
keithcurtis said: I'm not familiar at all with the script, but the macro in the code, the one that you bolded, is not the same as the one in your token action. The one from the code starts with "!spells", and the one in your action starts with "!picklevelspells". The initial code would not seem to allow for "!spells", but I only see snippets to work with. Scott C. said: Agree with Keith. Although, I notice that picklevelspells appears in your first snippet, but it is t clear how these work together. There is another issue though; there is a leading space in the token action version, which is why it's appearing in chat; the first character isn't an exclamation point, so it isn't treated as an API message. Thanks Keith and Scott. !spells is another script in the same mod. !picklevelspells is run when the "First, Click to Choose Spell Level". It verifies that the selected character token has at least one spell casting class and to set the choice of spells to match the spellcaster. If not, it returns a red chat message that declares: My understanding, which may well be incorrect, is that I cannot have the pick list in the same on("chat:message", function(msg) because it will execute to the end? Or will it suspend until the level is chosen? If yes to the last, I'll definitely change it, but for now, it works as written. Let me try to remove that leading space... And that does indeed work, thanks so much. Except my !picklevelspells is telling me an actual spellcaster has no spells listed.  Must poke at it a bit more.
One suggestion I would add is to use a key|value for your arguments, instead of requiring your args to be entered in a specific order. It makes your macros/commands a bit easier to read and troubleshoot, and means that the order of name/level/etc. doesn't matter in the command .  That would end up looking like this:   !picklevelspells --name|@{selected|character_id} --level|?{Spell Level |All Spells,all|Cantrips,0|1st Level,1|2nd Level,2|3rd Level,3|4th Level,4|5th Level,5|6th Level,6|7th Level,7}) If you share your full script code it would be easier/possible to help troubleshoot.
Jarren said: One suggestion I would add is to use a key|value for your arguments, instead of requiring your args to be entered in a specific order. It makes your macros/commands a bit easier to read and troubleshoot, and means that the order of name/level/etc. doesn't matter in the command .  That would end up looking like this:   !picklevelspells --name|@{selected|character_id} --level|?{Spell Level |All Spells,all|Cantrips,0|1st Level,1|2nd Level,2|3rd Level,3|4th Level,4|5th Level,5|6th Level,6|7th Level,7}) If you share your full script code it would be easier/possible to help troubleshoot. Well, it's over a 1000 lines long, including spaces and comments, of course. HOWEVER, I got the macro to work as per launching the spell button on the main menu: I honestly thought my macro script was similar to yours. See the image I did find a minor error though. The close parenthesis was not necessary at all and when I finally got the macro to do something the reason I got the errors I mention in response to Keith and Scott was because instead of feeding the second variable as "all", "0", "1", etc It was feeding "all)", "0)", "1)". Once I got rid of that close parenthesis, it all worked as it was meant to: Oh crumbs, I do need to add 8th and 9th level since this is generic and for all spell casters. In the actual mod code, I limit it to 7th except for magic users (AD&D 1e) who go to 9th level. I also have "Cantrips" or "Orisons" particular to the latter for clerics and druids instead of all together here. Thank you for everyone's help on this.