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

startRoll / Button Attribute / Character Sheet Attribute Help needed

1627164423

Edited 1627164483
Hello! I am working with a friend to make an automatic crit/fumble function that works when clicking on attributes/stats in the character sheet. I've got everything working as I'd like, except for when it comes to adding attribute/skill values to the roll. I've got the exploding dice working and they are sent to chat. My issue arises when I want to refer to a button attribute and use it when rolling. I'm not sure it can be done as I'd like, but I thought I'd ask. What I am trying to do is to call upon a custom attribute in my button. My button is currently: <button type='action' name="act_roller" data-i18n="awarenes-u" class='sheet-skill-roller''>AWARENESS</button> When I call on startRoll later, it looks thus: startRoll("&{template:roller} {{name=Roller}} {{roll=[[1d10+@{int}[STAT]+@{awareness_total}[SKILL]+?{ADDITIONAL MODS? (Bright Light, No Vision, Terrain etc)|0}[MOD]]]}} {{explode1=[[1d10]]}} {{explode2=[[1d10]]}} {{explode3=[[1d10]]}} {{explode4=[[1d10]]}} {{explode5=[[1d10]]}} {{explode6=[[1d10]]}} {{explode7=[[1d10]]}} {{explode8=[[1d10]]}} {{explode9=[[1d10]]}} {{explode10=[[1d10]]}}", (results) => { Ignore all the exploding dice. All that matters is the initial roll called "roll". As you can see, I'm asking it to add  @{int}   and  @{awareness_total}  as well as a custom modifier in the end. But I want to remove  @{int}   and  @{awareness_total}  to replace them with a placeholder.  What I'd like to do is something like: <button type='action' name="act_roller" attributeName="@{int}" skillName="@{awareness_total}" data-i18n="awarenes-u" class='sheet-skill-roller''>AWARENESS</button> in order to use a placeholder in the roll that then takes the attributes from the button: startRoll("&{template:roller} {{name=Roller}} {{roll=[[1d10+attributeName[STAT]+skillName[SKILL]+?{ADDITIONAL MODS? (Bright Light, No Vision, Terrain etc)|0}[MOD]]]}} {{explode1=[[1d10]]}} {{explode2=[[1d10]]}} {{explode3=[[1d10]]}} {{explode4=[[1d10]]}} {{explode5=[[1d10]]}} {{explode6=[[1d10]]}} {{explode7=[[1d10]]}} {{explode8=[[1d10]]}} {{explode9=[[1d10]]}} {{explode10=[[1d10]]}}", (results) => { By doing so, I'd avoid having to make the startRoll function for every skill and be able to simply call on it based on the information from the button. Can I do something like this? Any help would be appreciated.
1627175622

Edited 1627176362
Oosh
Sheet Author
API Scripter
You need some way of telling the roll which Attribute is being rolled. Is your button in a repeating section? If not, "act_roller" probably isn't going to work as a button, as the click event doesn't contain the information you need. So you either need a button per skill/ability, or it needs to be in a repeating section so you have the row ID attached to the click event. It's hard to tell without knowing what the sheet looks like - there's other ways to approach it, like having <select> elements contain the attribute/skill you'd like rolled, bu then you'd just call those @{attributes} stored in the <select> directly in your roll. You'd need this kind of approach if you want a single button for the entire sheet. From the looks of it, you've got a button per skill though (the normal way to do it). An example. We'll assume somewhere in your code you have declared all of your skills as an Array, const skillNames = ['awareness', ....]; You'd then change your buttons so they reference the skill in their name (since the button name gets passed to the event handler): <button type='action' name="act_roller_awareness" data-i18n="awarenes-u" class='sheet-skill-roller''>AWARENESS</button> You could then listen with something like this: const skillNames = ['awareness', 'axolotl_studies', 'burbling' ...] // an Array of all skills let skillTriggers = skillNames.map(sk => `clicked:roller_${sk}`); // create all your event listeners on(skillTriggers.join(' '), (ev) => { let skill = ev.triggerName.match(/roller_(.*)/)[1]; // isolate the skill name from the trigger console.log(`Sending "${skill}" click to roll function.`); myRollFunction(skill); // start the roll });
1627189793
GiGs
Pro
Sheet Author
API Scripter
Oosh said: You'd then change your buttons so they reference the skill in their name (since the button name gets passed to the event handler): <button type='action' name="act_roller_awareness" data-i18n="awarenes-u" class='sheet-skill-roller''>AWARENESS</button> You'd especially want to change the action button name from something generic like act_roller, as oosh as done here. Every button in your sheet should have a unique name, so it can be grabbed and dragged to the macro bar, and be used in macros. That said, it's best to avoid a second underscore in action button names, so act_roller-awareness would be better. Or just act_awareness . This is mainly for repeating sections - an underscore in an action button name will cause the button to fail. I think they work okay outside of a repeating section, but I never use them for consistency.
1627241216
Andreas J.
Forum Champion
Sheet Author
Translator
GiGs said: You'd especially want to change the action button name from something generic like act_roller, as oosh as done here. Every button in your sheet should have a unique name, so it can be grabbed and dragged to the macro bar, and be used in macros. Does this mean that even existing "act_" buttons that doesn't use the new parsing thing can be called in the chat, to activate sheetworkers to to whatever, and not just those that results in a dice roll?
1627242311
GiGs
Pro
Sheet Author
API Scripter
I see no reason action buttons wouldnt work in chat, as long as you remember to supply the character whose sheet to use. The new parsing thing doesn't add anything in that respect - it just adds an extra feature to roll20 features that already exist.
1627248292
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yep, action buttons can now do everything roll buttons can do with the current exception that you can't drag action buttons to the macro bar, which I'm hoping is a bug. I'd expect that as we move forward, roll buttons get relegated to the same position that autocalc fields are in; just a bit of legacy code that we don't use on new sheets.
1627273198
GiGs
Pro
Sheet Author
API Scripter
Scott C. said: I'd expect that as we move forward, roll buttons get relegated to the same position that autocalc fields are in; just a bit of legacy code that we don't use on new sheets. I hadn't thought that far ahead, but that makes a lot of sense.
1627280421

Edited 1627280450
Oosh
Sheet Author
API Scripter
Yeah there's not much reason to use one if you're doing a new sheet. It's quick and easy to add one, but you'll just need to replace it with an action button/startRoll() later if you want to do anything interesting with it. With some forethought to your action button naming convention, I guess you could even handle every roll on the sheet with a single listener, assembling the required function & parameters from the button name. That would be neat.