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

If/Else and formatting rolls. First time API user.

Hey Everyone, I'm trying to make my Serenity character sheet play nice with Roll20. Serenity works with die steps. So you increase from d2 up through d12+d12 depend on how badass you are. In order to be able to do any macro math I need to be able to do work with whole numbers. Currently the attributes are stored as whole numbers but I need to convert the whole number value over to the analogous dice roll. So 22 becomes "1d12 + 1d10". More specifically, if someone has an attribute of 20 then I need to check to see if the value is greater than 12. If True then I need to "/roll 1d12 + 1d" + (@{Attribute}-12} to display roll for that stat. Else "/roll 1d" + @{Attribute} In code-ish: If ( @{Attribute} > 12 ) { Print "/roll 1d12 + 1d" + (@{Attribute} - 12) } Else { Print "/roll 1d" + @{Attribute} } Please excuse my syntax, I'm sure it's atrocious. It's been 15 years since I've coded for real and a lot of that knowledge has been replaced with Stranger Things episodes, parenting, and bad politics. Anyone who has experience utilizing the API or simple javascript in custom character sheets I'd love to hear from you. I've googled and I can find scripts for days but very little information on how to implement them.
1477265635
The Aaron
Pro
API Scripter
What you probably want is the modulus operator: %  Something like: var d12s=attribute%12; attribute-=(d12s*12); var d10s=attribute%10; attribute-=(d10s*10); var d8s=attribute%8; attribute-=(d8s*8); var d6s=attribute%6; attribute-=(d6s*6); var d4s=attribute%4; attribute-=(d4s*4); var d2s=attribute%2; attribute-=(d2s*2); var cmd=d2s+'d2 + '+ d4s+'d4 + '+ d6s+'d6 + '+ d8s+'d8 + '+ d10s+'d10 + '+ d12s+'d12';
Awesome, thanks for replying. So is this done in the actual character sheet or is there a separate script that I'm supposed to link up to the character sheet somehow. Please excuse me if I'm being dense but it's my first trip down this particular rabbit hole. 
1477266412
The Aaron
Pro
API Scripter
That's a good question.  I'd probably suggest setting this all up inside a character sheet with Sheet Workers and Roll Templates.
Okay cool, I've been looking at Roll Templates and see how those work for the most part. Sheet Workers I'm unfamiliar with but at least I'm pointed in the right direction. Are the similar to functions? Any tips for working with them before I go harass the wiki some more?
1477267917
The Aaron
Pro
API Scripter
They are a collection of event handlers, probably best to start with the wiki page:&nbsp; <a href="https://wiki.roll20.net/Sheet_Worker_Scripts" rel="nofollow">https://wiki.roll20.net/Sheet_Worker_Scripts</a> Then ask questions in Character Sheets, or possibly API.
1477268358
Lithl
Pro
Sheet Author
API Scripter
Sheet workers trigger off changing attributes, and can change attributes in turn. So you could trigger on changing one attribute (eg, value changes to 22), and then set some hidden attribute to "d12+d10", constructed like in Aaron's example. Then the macro/roll button uses that hidden attribute to make the roll.
Okay, I'll work on that. Thanks guys.&nbsp; If anyone else has direction I welcome all of it.&nbsp;