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

Custom character sheet: any way to call macro from sheet button?

January 28 (3 years ago)
Joel
Pro

I'm making my own character sheet, everything is going fine as far as layout and attributes, etc... the only issue I wish I could solve is that I would like a number of buttons in the character sheet to call a macro. I've been using multiple instances of button[type="roll"] to display a roll like this...

&{template:default} {{name=@{ranged_weapon1}}} {{To Hit=[[1d100cf>98cs<02]]}} {{Dex + Skill=[[@{dm}+@{rw_skill_1}]]}} {{Range=@{rw_range_1}}}{{Max Damage=@{rw_damage_1}}} {{SEU Use=@{rw_seu_1}}} {{Rate of Fire=@{rw_rof_1}}} {{Defense=@{rw_defense_1}}} {{Spare Clips=@{rw_qty_1}}} {{Ammo In Clip=@{rw_ammo_1}}}

but I would much rather just have the button call up a macro like #ranged-weapon-attack-1

I see in the wiki it says you can't use a button to call macros or put anything in chat, just curious if anyone has found a work-around, or maybe it technically can work and I had some syntax issues when I was experimenting with it.

If it is possible for a button in the character sheet to call for a specific macro, what does that syntax look like?

January 28 (3 years ago)
GiGs
Pro
Sheet Author
API Scripter

Unfortunately it's not possible, Code built-in to a sheet can only refer tothe sheet itself, and can't call macros from outside the sheet.

You can manually add an ability on the Attributes & Abilities tab to call a macro, but that's not in the sheet code.

January 28 (3 years ago)
Joel
Pro

I did populate a sheet's "Abilities" tab with what-would-have-been my macro, but then could not find a way to trigger it from the main character sheet. That would be a perfectly acceptable solution for me, if I can trigger the Ability from the main sheet. I searched, didn't find an answer, then experimented but couldn't find a way to make it work. (I'm guessing there isn't a way, otherwise you could set an Ability to call up #my-macro and then trigger the Ability from the main sheet.)


January 28 (3 years ago)
GiGs
Pro
Sheet Author
API Scripter

Unfortunately it can't be done. The sheet's code is isolated from everything else in roll20, including the attribute & abilities tab.

I'm not sure what you are trying to do this for. Is there a reason you don't want to include that macro directly in the sheet code?

January 28 (3 years ago)

Edited January 28 (3 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

It seems to me your actual goal is to limit how many times you need to repeat the same macro code. You can actually do that in a sheet's code by simply storing the roll output in an attribute and then just referencing that attribute in any button that needs to call it. Something like:

<input type="hidden" name="attr_chat_output" value="&{template:default} {{name=@{ranged_weapon1}}} {{To Hit=[[1d100cf>98cs<02]]}} {{Dex + Skill=[[@{dm}+@{rw_skill_1}]]}} {{Range=@{rw_range_1}}}{{Max Damage=@{rw_damage_1}}} {{SEU Use=@{rw_seu_1}}} {{Rate of Fire=@{rw_rof_1}}} {{Defense=@{rw_defense_1}}} {{Spare Clips=@{rw_qty_1}}} {{Ammo In Clip=@{rw_ammo_1}}}">
<button type="roll" name="roll_roll_1" value="@{chat_output}">Roll macro</button>
<button type="roll" name="roll_roll_2" value="@{chat_output}">Roll macro</button>
<button type="roll" name="roll_roll_3" value="@{chat_output} {{Pithy Quote=You can even addend things onto the macro like so}}">Roll macro with pithy quote</button>

We also have the powerful custom roll parsing feature that can let you build that output dynamically each time the button is clicked. It requires that the buttons be action buttons and uses javascript, but is extremely powerful and much more flexible than roll buttons.

EDIT: If your goal is to allow players to directly edit the macro, then the same technique applies, just use a textarea instead of a hidden input for the chat_output attribute.

January 28 (3 years ago)
Joel
Pro


GiGs said:

Unfortunately it can't be done. The sheet's code is isolated from everything else in roll20, including the attribute & abilities tab.

I'm not sure what you are trying to do this for. Is there a reason you don't want to include that macro directly in the sheet code?

I thought of several uses for it, for example, it's a game without a compendium on roll20 and I was trying out various ways to imitate filling in multiple fields quickly when they gain a new weapon or skill (like dragging and dropping an item onto your sheet). One possible solution was to have one macro for each weapon, then no one needs to drag the whole weapon and all its info onto their sheet, if instead they simply had a button with the weapon's name, and when they click it, it would trigger the macro that has the roll and all the weapon stats, column shifts, damage, etc. Same idea for skills, sort of like how the roll200 D&D 5e sheet lets you click on a skill to put the text of it in chat, I thought I could do that with a macro, just do it one time and always reference those skill macros from buttons.


That's alright, since it wasn't going to work I just spent a few hours getting all those weapon stats onto the sheet. Macro would have just been easier, and if I needed to make a change or fix a mistake, I would only need to fix it in one place.

thanks for your help.

January 28 (3 years ago)
Joel
Pro


Scott C. said:

It seems to me your actual goal is to limit how many times you need to repeat the same macro code. You can actually do that in a sheet's code by simply storing the roll output in an attribute and then just referencing that attribute in any button that needs to call it. Something like:

<input type="hidden" name="attr_chat_output" value="&{template:default} {{name=@{ranged_weapon1}}} {{To Hit=[[1d100cf>98cs<02]]}} {{Dex + Skill=[[@{dm}+@{rw_skill_1}]]}} {{Range=@{rw_range_1}}}{{Max Damage=@{rw_damage_1}}} {{SEU Use=@{rw_seu_1}}} {{Rate of Fire=@{rw_rof_1}}} {{Defense=@{rw_defense_1}}} {{Spare Clips=@{rw_qty_1}}} {{Ammo In Clip=@{rw_ammo_1}}}">
<button type="roll" name="roll_roll_1" value="@{chat_output}">Roll macro</button>
<button type="roll" name="roll_roll_2" value="@{chat_output}">Roll macro</button>
<button type="roll" name="roll_roll_3" value="@{chat_output} {{Pithy Quote=You can even addend things onto the macro like so}}">Roll macro with pithy quote</button>

We also have the powerful custom roll parsing feature that can let you build that output dynamically each time the button is clicked. It requires that the buttons be action buttons and uses javascript, but is extremely powerful and much more flexible than roll buttons.

EDIT: If your goal is to allow players to directly edit the macro, then the same technique applies, just use a textarea instead of a hidden input for the chat_output attribute.


Oh excellent, thank you!



January 28 (3 years ago)

Edited January 28 (3 years ago)
Joel
Pro


The idea was (for example) instead of having to write at least 12 different variations of the same thing in the HTML (stat rows for each weapon) just put each weapon's stats in its own individual macro and call it from a button on the sheet. The only things that are needed from the sheet are easy to get someplace else (weapons skill level, and amount of ammo on hand).

All in all, for my first character sheet, I'm reasonably happy, all the important stuff is automated now, and with Scott's trick I'll have some more flexibility going forward.

January 28 (3 years ago)
Joel
Pro

My next ambition is figuring out how sheets make rolls from clickable text, like clicking on your weapon name in the 5e sheet, instead of having to put the little gray dice button next to each weapon name. Or clicking on the text of a skill name rolls for that skill, instead of having to click a little icon next to the name. I'll get there eventually, LOL.

January 28 (3 years ago)
Finderski
Pro
Sheet Author
Compendium Curator


Joel said:

My next ambition is figuring out how sheets make rolls from clickable text, like clicking on your weapon name in the 5e sheet, instead of having to put the little gray dice button next to each weapon name. Or clicking on the text of a skill name rolls for that skill, instead of having to click a little icon next to the name. I'll get there eventually, LOL.


Easier than you think...those are just buttons that are formatted to not look like buttons...

January 28 (3 years ago)

Edited January 28 (3 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

Joel said:

The idea was (for example) instead of having to write at least 12 different variations of the same thing in the HTML (stat rows for each weapon) just put each weapon's stats in its own individual macro and call it from a button on the sheet. The only things that are needed from the sheet are easy to get someplace else (weapons skill level, and amount of ammo on hand).

It's late to do it, since it looks like you've got a mostly complete sheet, but PUG (and to a lesser extent SCSS) really make things like this easy.

Edit: As for the buttons, as Finderski said, it's just styling the button. You can inspect the button to see what styles are applied to it and what you want to remove. I believe it's background-color, box-shadow, padding, and maybe a margin that you'll want to change. In addition, you'll want to set the :before element's content to "".

January 28 (3 years ago)
Joel
Pro

Thanks a lot. I'm learning by doing, as they say. Don't know PUG or SCSS or java script either (or, yet?), trying to do as much as I can with what HTML and CSS I've figured out. Really appreciate it.