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

Nesting Macros

Hi all. I am  using macros like this to do ability checks: &{template:default} {{name=Strength Check}} {{ @{target|Target1|character_name}= [[1d20 + @{target|Target1|strength_mod}]] }} {{ @{target|Target2|character_name}= [[1d20 + @{target|Target2|strength_mod}]] }} {{ @{target|Target3|character_name}= [[1d20 + @{target|Target3|strength_mod}]] }} It works fine and gives a nice easy to read result.  But (in this example) it's hardcoded to 3 targets and to one ability score.   So I thought I would create some uber-marcros to call the appropriate sub-macro.  E.G.: ?{STAT|STR, #DC-STR-3 | DEX, #DC-DEX-3} But when I do this, it renders the nested macro in the dropdown (and breaks the drop-down), like: If I take out the template related stuff in my sub-macros, it will work but then I lose the nice table formatting: @{target|Target1|character_name}= [[1d20 + @{target|Target1|strength_mod}]]  @{target|Target2|character_name}= [[1d20 + @{target|Target2|strength_mod}]]  @{target|Target3|character_name}= [[1d20 + @{target|Target3|strength_mod}]] I've been experimenting with HTML replacement but haven't had any luck.  Is it possible to use the full template in my sub-macro?  Just trying to do something simple that works for my game, not looking to get into something complicated like the GroupCheck API/Mod.
1702511135

Edited 1702511879
A related question: I was advised in another thread regarding duplicating similar monsters that a good idea would be to create one character sheet and then instantiate several versions of that monster and use token markers or whatever to differentiate them.  But if I want to have those multiple monsters do a saving throw using my macros, it seems it'll only show one result.   So if I have a goblin character sheet and 3 such goblins on the board, when I try to get them to roll saves vs. fireball or whatever, it'll only show one result using my macro.   I guess the "target" option doesn't work well with that and I should go back to using multiple character sheets or give up on doing checks this way?
1702511176

Edited 1702511390
Gauss
Forum Champion
Short version, use a Chat Menu Long version, when you put a query in, especially one with macros inside of it, you are putting the contents of those macros into your query, that breaks the query.  The system does not see this: ?{query name|#macro} It sees this:  ?{query name|macro contents which break the query} The moment the system hits a "|" or a "," or a "}" in your macro contents it is telling the query that it has hit a "|" or a "," or a "}", and that breaks the query.  You can replace all the control characters in your macro with html entities, but that is laborious and not recommended. Use Chat Menus instead. :)
1702511256
Gauss
Forum Champion
fnord12 said: A related question: I was advised in another thread regarding duplicating similar monsters that a good idea would be to create one character sheet and then instantiate several versions of that monster and use token markers or whatever to differentiate them.  But if I want to have those multiple monsters do a saving throw using my macros, it seems it'll only show one result.   So if I have a goblin character sheet and 3 such goblins on the board, when I try to get them to roll saves vs. fireball or whatever, it'll only show one result using my macro.   I guess the "target" option doesn't work well with that and I should go back to using multiple character sheets or giving up on doing checks this way? I don't understand the problem you are having, could you elaborate?  Target should work fine for targeting a token linked to a character sheet. 
Thanks for the link to Chat Menus, Gauss, I wasn't aware of them and I will look into them. Regarding my second comment, imagine I have a character sheet for Goblin and I drag that onto the map 3 times, putting 3 goblins on the board.  Now I run my first macro, which you can see calls for Target1, Target2, Target3.  So when I run the macro, Roll20 asks me to click on Target1, Target2, and Target3.  But after doing that, in my template in the chat, I only see the result for one Goblin.
1702516044

Edited 1702516902
Gauss
Forum Champion
fnord12 said: Thanks for the link to Chat Menus, Gauss, I wasn't aware of them and I will look into them. Regarding my second comment, imagine I have a character sheet for Goblin and I drag that onto the map 3 times, putting 3 goblins on the board.  Now I run my first macro, which you can see calls for Target1, Target2, Target3.  So when I run the macro, Roll20 asks me to click on Target1, Target2, and Target3.  But after doing that, in my template in the chat, I only see the result for one Goblin. Switch character_name for token_name. Then it should work, if you are using individualized token names.  Example: Goblin1, Goblin2, Goblin3, etc The same character (or token) name seems to be confusing the system.  Note: if you are not using individualized token names, then there will need to be a different solution. Remove the naming target section altogether. Replace it with something static, such as Token1, Token2, Token3. Example:  &{template:default} {{name=Strength Check}} {{Target1=[[1d20 + @{target|Target1|strength_mod}]] }} {{Target2=[[1d20 + @{target|Target2|strength_mod}]] }} {{Target3=[[1d20 + @{target|Target3|strength_mod}]] }}
1702521059

Edited 1702521087
Reporting back that changing the character Name field (the one under Token settings) doesn't work.   It seems to merge the results under the Represents Character name no matter what.  But if i do change it to static Token1, etc., then they do display separately.  Not really helpful to me though so i think I'm back to one character sheet per token.   Thanks for your help!
1702523796

Edited 1702523901
Gauss
Forum Champion
fnord12 said: Reporting back that changing the character Name field (the one under Token settings) doesn't work.   It seems to merge the results under the Represents Character name no matter what.  But if i do change it to static Token1, etc., then they do display separately.  Not really helpful to me though so i think I'm back to one character sheet per token.   Thanks for your help! As I explained, you would need to use individualized token names for that.  Since you have a pro account, you could find or ask someone to make a script which takes all selected tokens and appends their names with a number afterwards. That will make it faster to individualize the names.  I cannot stress enough that you really want to avoid using one character sheet per token, it is going to be a major drain on system resources. 
1702524664
The Aaron
Roll20 Production Team
API Scripter
Here's a script that will append a number to all the selected tokens.  It's not overly intelligent, it just blindly adds " 1" " 2" etc to the end of each selected token, but give it a try and see if it works for your use case, and maybe we can expand it to make it nicer. Select all the tokens and run: !number Code: on('ready', ()=>{ on('chat:message', msg=>{ if('api' === msg.type && playerIsGM(msg.playerid) && /^!number(\b\s|$)/i.test(msg.content)){ let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); let n = 0; (msg.selected || []) .map(o=>getObj('graphic',o._id)) .filter(g=>undefined !== g) .forEach(g=>g.set({ name: `${g.get('name')} ${++n}` })); sendChat('Numbered',`/w "${who}" Renumbered ${n} tokens.`); } }); });
1702524858
The Aaron
Roll20 Production Team
API Scripter
Here's one that's a little smarter.  It will rebuild the names of tokens if they represent a character, and number individually all the tokens representing that character: Command: !renumber-selected Code: on('ready',()=>{ on('chat:message',msg=>{ if('api'===msg.type && /^!renumber-selected(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){ let args = msg.content.split(/\s+/); let numBase = (parseInt(args[1])||1)-1; let tcmap = (msg.selected || []) .map(o=>getObj('graphic',o._id)) .filter(g=>undefined !== g) .reduce((m,t)=>{ const rep=t.get('represents')||'%%NOCHAR%%'; m[rep]=m[rep]||[]; m[rep].push(t); return m; },{}); Object.keys(tcmap).forEach( c => { let ts = tcmap[c]; let n = numBase; let numer = (t) => { let baseName = t.get('name').replace(/\s+\d*$/,''); t.set('name', `${baseName} ${++n}`); }; if('%%NOCHAR%%' !== c){ // number character tokens let character = getObj('character',c); if(c) { numer = (t) => { t.set('name', `${character.get('name')} ${++n}`); }; } } ts.forEach(numer); }); } }); });
1702527058

Edited 1702527318
I don't think Gauss understood me in my post above.  I DID rename each of the tokens as I described, but the results were still merged by the Represents name.  Same thing with The Aaron's script; it successfully renames the tokens but doesn't affect the results in the chat.  So here's 3 tokens from the same character sheet ("Bounder") which were renamed by The Aaron's script: And I see 3 dice rolled.   But in the chat it's just grouped by the Represents/Character Sheet name: If I run my same macro on three tokens with distinct character sheets, then I'll get 3 rows as expected. It is what it is.  But then I'm curious about the resource issue.   Is it a problem to just have a large library of character sheets?  Because I hope to do that anyway.  Or is it just that you shouldn't have too many tokens calling different character sheets on the map at the same time ?   Update: Wrote this after testing with The Aaron's first script, but I think the results will be the same.   I really appreciate the script help!
Oh wait sorry I misunderstood Gauss.  I'm supposed to update my script to use  token_name instead of  character_name.   I missed that and now it works, and The Aaron's script can help me rename them quickly.  Thank you both!
1702527680

Edited 1702527696
Gauss
Forum Champion
In my testing it works as I described.  Could you please repost the macro that is not working? Edit: n/m :)
1702531725
timmaugh
Forum Champion
API Scripter
BTW, you can use macros in your queries if you do it with Fetch. Provided all of the macros are as you showed (a non-script template-based result), then the following would work: !?{STAT|STR,#(DC-STR-3)|DEX,#(DC-DEX-3)}{&simple} By using Fetch constructions instead of Roll20 constructions, you don't have the expansions into the query syntax like how Gauss was describing, above. Instead, the query resolves and leaves only one Fetch construction... then Fetch resolves that reference and gets the appropriate macro text. If your macros are a mix of script and non-script calls, we can still make it work... it will just take a bit of rearranging. Fetch is a part of the MetaScriptToolbox script set (available from the 1-click). Also, if you get the MetaScriptToolbox and TokenMod, you can run select tokens on a page and run something like this to rename them (including an index number): !forselected(^) token-mod --set name|"@^(selected.token_name) {&i}"