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

managing Repeating resource macro output when that line does not exists

Hi I've set up a macro to see stats of a selected PC without having to open the sheet. I have a problem on repeating resources when they are not there in one of the PC I use a very straightforward  {{@{selected|repeating_resource_$0_resource_left_name}=@{selected|repeating_resource_$0_resource_left}/@{selected|repeating_resource_$0_resource_left|max}}}  but if those fields are not present on the PC I get just the text like in the image below there is any way to have them not appear if not present in the sheet? is the &{no error} useful in this case? if so where should it go? thanks Andrea
It's possible, but it depends on which character sheet you are using (and which game you are playing), and what template format you want it to use and how you want it to look. Here's some examples for 5th Edition D&D using the D&D 5E by Roll20 character sheet: Player Inventory NPC Stats
yes sorry I should have added that I am using dnd 5E
Jarren said: It's possible, but it depends on which character sheet you are using (and which game you are playing), and what template format you want it to use and how you want it to look. Here's some examples for 5th Edition D&D using the D&D 5E by Roll20 character sheet: Player Inventory NPC Stats hi Jarren I did look at your item macro and seems usable to adapt to my scope but I do not understand which is the piece that allows to just show the existing items. I've run your macro on a character with six items and stops fine even if your macro goes to $9
1636049160

Edited 1636049701
It's using the HTML Styles in Chat trick that Oosh explains here . Basically, you're creating a 'button' with the text of the attribute names and 'injecting' some html style to force it to only display when it is present. Basic API button: [Button Name](buttonlink) API button with styling: [Button Name](buttonlink " style="") API button with styling that prevents it from displaying at all: [Button Name](buttonlink " style="display:none;") API button with styling that prevents it from displaying when an attribute is missing: [Button Name](buttonlink " style="display:block; display:none@{selected|ATTRIBUTENAME|max};") What happens is you don't have an attribute named 'ATTRIBUTENAME', there is no 'max' field, so an error message gets pulled instead. So the style becomes style="display:block; display:noneERRORMESSAGE;" and the display:block; is kept and used.  If there was an attribute called 'ATTRIBUTENAME', and it doesn't use the 'max' field (most don't), then it becomes style="display:block; display:none ;" and whatever the last version of an attribute in a style tag is what will be used, so the 'none' overrides the 'block', and the button isn't displayed. At that point it's an issue of knowing what all the correct attribute names are, and getting the correct order of the style tags so they cancel out in the way you want.  I started by doing it all manually (which is a pain the butt) and just incrementally adding more $#, then figured it would be easier to just create an excel spreadsheet that does the incrementing for me.  That ends up being about the same amount of work. One issue for the macro you want to create is that the repeating resource fields do  use the max field.
1636051269

Edited 1636051337
Ok this will work for up to 10 resource fields (5 left and 5 right): /w gm &{template:npcaction} {{rname=@{selected|token_name}}} {{name=Resources}} {{description=[-- Resources --](" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: #7e2d40; font-weight: bold; white-space: pre; display: none; display: block@{selected|repeating_resource_$0_resource_left_name|max};)[@{selected|repeating_resource_$0_resource_left_name} = @{selected|repeating_resource_$0_resource_left} / @{selected|repeating_resource_$0_resource_left|max}  ](" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: black; display: none; display: block@{selected|repeating_resource_$0_resource_left_name|max};)[@{selected|repeating_resource_$0_resource_right_name} = @{selected|repeating_resource_$0_resource_right} / @{selected|repeating_resource_$0_resource_right|max}  ](" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: black; display: none; display: block@{selected|repeating_resource_$0_resource_right_name|max};)[@{selected|repeating_resource_$1_resource_left_name} = @{selected|repeating_resource_$1_resource_left} / @{selected|repeating_resource_$1_resource_left|max}  ](" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: black; display: none; display: block@{selected|repeating_resource_$1_resource_left_name|max};)[@{selected|repeating_resource_$1_resource_right_name} = @{selected|repeating_resource_$1_resource_right} / @{selected|repeating_resource_$1_resource_right|max}  ](" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: black; display: none; display: block@{selected|repeating_resource_$1_resource_right_name|max};)[@{selected|repeating_resource_$2_resource_left_name} = @{selected|repeating_resource_$2_resource_left} / @{selected|repeating_resource_$2_resource_left|max}  ](" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: black; display: none; display: block@{selected|repeating_resource_$2_resource_left_name|max};)[@{selected|repeating_resource_$2_resource_right_name} = @{selected|repeating_resource_$2_resource_right} / @{selected|repeating_resource_$2_resource_right|max}  ](" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: black; display: none; display: block@{selected|repeating_resource_$2_resource_right_name|max};)[@{selected|repeating_resource_$3_resource_left_name} = @{selected|repeating_resource_$3_resource_left} / @{selected|repeating_resource_$3_resource_left|max}  ](" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: black; display: none; display: block@{selected|repeating_resource_$3_resource_left_name|max};)[@{selected|repeating_resource_$3_resource_right_name} = @{selected|repeating_resource_$3_resource_right} / @{selected|repeating_resource_$3_resource_right|max}  ](" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: black; display: none; display: block@{selected|repeating_resource_$3_resource_right_name|max};)[@{selected|repeating_resource_$4_resource_left_name} = @{selected|repeating_resource_$4_resource_left} / @{selected|repeating_resource_$4_resource_left|max}  ](" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: black; display: none; display: block@{selected|repeating_resource_$4_resource_left_name|max};)[@{selected|repeating_resource_$4_resource_right_name} = @{selected|repeating_resource_$4_resource_right} / @{selected|repeating_resource_$4_resource_right|max}  ](" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: black; display: none; display: block@{selected|repeating_resource_$4_resource_right_name|max};)[@{selected|repeating_resource_$5_resource_left_name} = @{selected|repeating_resource_$5_resource_left} / @{selected|repeating_resource_$5_resource_left|max}  ](" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: black; display: none; display: block@{selected|repeating_resource_$5_resource_left_name|max};)[@{selected|repeating_resource_$5_resource_right_name} = @{selected|repeating_resource_$5_resource_right} / @{selected|repeating_resource_$5_resource_right|max}  ](" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: black; display: none; display: block@{selected|repeating_resource_$5_resource_right_name|max};)}} &{noerror} If you want to use this in a collection macro, you need to create two macros.  Create a macro named 'ResourcesMacro' with that code in it. Do not make 'ResourcesMacro' visible in the macrobar or as a token action. Then create another macro named 'Resources' with this code and make it visible in the macrobar or as a token action: #ResourcesMacro &{noerror} As it's currently set up, it will simply whisper to the GM.  If you want this to be usable by your players it'll need a little more tweaking.
WOW! thanks! one last question as you have been very kind! in your example you have a (style) parenthesis after each [selected] but also a starting (style) at the beginning.  basically you have 2 (style) for the left $0 block and the only the (style) after each other. why is that necessary?
[-- Resources --] Is just for the header  (" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: #7e2d40; font-weight: bold; white-space: pre; display: none; display: block@{selected|repeating_resource_$0_resource_left_name|max};) Is to style the header to make it the red color [@{selected|repeating_resource_$0_resource_left_name} = @{selected|repeating_resource_$0_resource_left} / @{selected|repeating_resource_$0_resource_left|max}  ] Is the first Left Resource name and current versus max number (" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: black; display: none; display: block@{selected|repeating_resource_$0_resource_left_name|max};) Is the code to make it only appear when it is present. [@{selected|repeating_resource_$0_resource_right_name} = @{selected|repeating_resource_$0_resource_right} / @{selected|repeating_resource_$0_resource_right|max}  ] Is the first Right Resource name and current versus max number (" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: black; display: none; display: block@{selected|repeating_resource_$0_resource_right_name|max};) Is the code to make it only appear when it is present.
thank you that is brilliant this is my final output for a player quick status check thanks again &{template:npcaction} {{rname=@{selected|token_name}}} {{name=Status}} {{description=[-- base --](" style=" color: #cc0000; font-weight: bold; display: block;)[HP = @{selected|hp} / @{selected|hp|max}  ](" style=" color: black;display: block;)[Temp HP = @{selected|hp_temp}  ](" style=" color: black;display: block; display: none@{selected|hp_temp};)[-- Resources --](" style="color: #7e2d40; font-weight: bold; display: block;)[@{selected|class_resource_name}= @{selected|class_resource} / @{selected|class_resource|max} ](" style=" color: black;display: block;display: none@{selected|class_resource_name};)[@{selected|other_resource_name}= @{selected|other_resource} / @{selected|other_resource|max} ](" style="color: black;display: block;display: none@{selected|other_resource_name};)[@{selected|repeating_resource_$0_resource_left_name}= @{selected|repeating_resource_$0_resource_left} / @{selected|repeating_resource_$0_resource_left|max} ](" style="color: black; display: none; display: block@{selected|repeating_resource_$0_resource_left_name|max};)[@{selected|repeating_resource_$0_resource_right_name} = @{selected|repeating_resource_$0_resource_right} / @{selected|repeating_resource_$0_resource_right|max}  ](" style="color: black; display: none; display: block@{selected|repeating_resource_$0_resource_right_name|max};display: none@{selected|repeating_resource_$0_resource_right_name};)[@{selected|repeating_resource_$1_resource_left_name} = @{selected|repeating_resource_$1_resource_left} / @{selected|repeating_resource_$1_resource_left|max}  ](" style="color: black; display: none; display: block@{selected|repeating_resource_$1_resource_left_name|max};)[@{selected|repeating_resource_$1_resource_right_name} = @{selected|repeating_resource_$1_resource_right} / @{selected|repeating_resource_$1_resource_right|max}  ](" style="color: black; display: none; display: block@{selected|repeating_resource_$1_resource_right_name|max};display: none@{selected|repeating_resource_$1_resource_right_name};)[@{selected|repeating_resource_$2_resource_left_name} = @{selected|repeating_resource_$2_resource_left} / @{selected|repeating_resource_$2_resource_left|max}  ](" style=" color: black; display: none; display: block@{selected|repeating_resource_$2_resource_left_name|max};)[@{selected|repeating_resource_$2_resource_right_name} = @{selected|repeating_resource_$2_resource_right} / @{selected|repeating_resource_$2_resource_right|max}  ](" style="color: black; display: none; display: block@{selected|repeating_resource_$2_resource_right_name|max}; display: none@{selected|repeating_resource_$2_resource_right_name};)[@{selected|repeating_resource_$3_resource_left_name} = @{selected|repeating_resource_$3_resource_left} / @{selected|repeating_resource_$3_resource_left|max}  ](" style="color: black; display: none; display: block@{selected|repeating_resource_$3_resource_left_name|max};)[@{selected|repeating_resource_$3_resource_right_name} = @{selected|repeating_resource_$3_resource_right} / @{selected|repeating_resource_$3_resource_right|max}  ](" style="color: black; display: none; display: block@{selected|repeating_resource_$3_resource_right_name|max};display: none@{selected|repeating_resource_$3_resource_right_name};)[@{selected|repeating_resource_$4_resource_left_name} = @{selected|repeating_resource_$4_resource_left} / @{selected|repeating_resource_$4_resource_left|max}  ](" style="color: black; display: none; display: block@{selected|repeating_resource_$4_resource_left_name|max};)[@{selected|repeating_resource_$4_resource_right_name} = @{selected|repeating_resource_$4_resource_right} / @{selected|repeating_resource_$4_resource_right|max}  ](" style="color: black; display: none; display: block@{selected|repeating_resource_$4_resource_right_name|max};display: none@{selected|repeating_resource_$4_resource_right_name};)[@{selected|repeating_resource_$5_resource_left_name} = @{selected|repeating_resource_$5_resource_left} / @{selected|repeating_resource_$5_resource_left|max}  ](" style="color: black; display: none; display: block@{selected|repeating_resource_$5_resource_left_name|max};)[@{selected|repeating_resource_$5_resource_right_name} = @{selected|repeating_resource_$5_resource_right} / @{selected|repeating_resource_$5_resource_right|max}  ](" style="color: black; display: none; display: block@{selected|repeating_resource_$5_resource_right_name|max};display: none@{selected|repeating_resource_$5_resource_right_name};)[-- Spells --](" style="color: #3d85c6; font-weight: bold; display: none;display: block@{selected|repeating_spell-1_$0_spellname|max};)[Spells L1= @{selected|lvl1_slots_expended}/@{selected|lvl1_slots_total}](" style="color: black; display: none;display: block@{selected|repeating_spell-1_$0_spellname|max};)[Spells L2= @{selected|lvl2_slots_expended}/@{selected|lvl2_slots_total}](" style="color: black; display: none;display: block@{selected|repeating_spell-2_$0_spellname|max};) [Spells L3= @{selected|lvl3_slots_expended}/@{selected|lvl3_slots_total}](" style=" color: black; display: none;display: block@{selected|repeating_spell-3_$0_spellname|max};)  [Spells L4= @{selected|lvl4_slots_expended}/@{selected|lvl4_slots_total}](" style="color: black; display: none;display: block@{selected|repeating_spell-4_$0_spellname|max};)  [Spells L5= @{selected|lvl5_slots_expended}/@{selected|lvl5_slots_total}](" style="color: black; display: none;display: block@{selected|repeating_spell-5_$0_spellname|max};) [Spells L6= @{selected|lvl6_slots_expended}/@{selected|lvl6_slots_total}](" style=" color: black; display: none;display: block@{selected|repeating_spell-6_$0_spellname|max};)  [Spells L7= @{selected|lvl7_slots_expended}/@{selected|lvl7_slots_total}](" style="color: black; display: none;display: block@{selected|repeating_spell-7_$0_spellname|max};) [Spells L8= @{selected|lvl8_slots_expended}/@{selected|lvl8_slots_total}](" style="color: black; display: none;display: block@{selected|repeating_spell-8_$0_spellname|max};)[Spells L9= @{selected|lvl9_slots_expended}/@{selected|lvl9_slots_total}](" style="text-decoration: none; background: none; background-color: transparent; border: none; padding: 0px; color: black; display: none;display: block@{selected|repeating_spell-9_$0_spellname|max};)  }} &{noerror}