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

API to effect character Attribute based on Spells being cast.

So, I'm gonna come right out and say that I have read through the API info, but nothing is retaining. I feel like I'm reading another language here. Here's my desire. In my system, players use Energy Points to use their talents or cast spells. For ease of my players, I was hoping to create an API so that when they would use a particular talent, they could just click a button and it would automatically spend the necessary EP and edit their tokens current EP automatically. Here is the current setup I have for spells that could be used. <h2>Spells</h2>  <fieldset class="repeating_spells">  Spell Title <input type="text" name="attr_Spell" /> Total EP Cost <input type="number" name="attr_EP_Cost" value="@{EffectEP}+@{CTEP}+@{DurationEP}+@{RangeEP}+@{AoEEP}+@{SpecEP}" disabled="true"/> <br> Effect <input type="text" name="attr_Effect" /> EP <input type="number" name="attr_EffectEP" value="0" /> <br> Casting Time <select name="attr_CT" class="CT">     <option value = "0">Single</option>     <option value = "3">Swift</option>     <option value = "10">Free</option> </select> EP <input type="number" name="attr_CTEP" value="@{CT}" disabled="true" /> Duration <input type="text" name="attr_Duration" /> EP <input type="number" name="attr_DurationEP" value="0" /> <br> Range <input type="number" name="attr_SpRange" />ft      EP <input type="number" name="attr_RangeEP" value="floor(@{SpRange}/25)" disabled="true"/> Area of Effect <input type="text" name="attr_AoE" /> EP <input type="number" name="attr_AoEEP" value="0" /> <br> Special <select name="attr_Spec" class="Spec">     <option value = "0"></option>     <option value = "1">Bouncing</option>     <option value = "2">Contingency</option>     <option value = "3">Draining</option>     <option value = "4">Empower</option>     <option value = "5">Maximize</option>     <option value = "6">Persistent</option>     <option value = "7">Selective</option>     <option value = "8">Sneaky</option>     <option value = "9">Trap</option>     <option value = "10">Vampiric</option> </select> EP <input type="number" name="attr_SpecEP" value="0"/> <br><br> </fieldset> The field that I would want to use would be @{EP_cost}, but I'm also having trouble with pulling attributes from fieldsets like this so that's another problem. Currently EP is not an attribute on the character sheets as I'm having to rewrite the code for it in order to make it properly autocalculate, but it would be something along the lines of @{MaxEP}, but then I honestly don't know how to make it access the current EP, rather than the max EP. Again, I read some of the info on the API page and I believe the was a SetCharAttr function that I would need to use, but that's about as far as I got. Any help is appreciated for my currently helpless self.
1572701555
GiGs
Pro
Sheet Author
API Scripter
If you're planning to treat attributes as numbers that you can edit, or grab for use in scripts, you need to use sheet workers to calculate them, not autocalc fields.  Scripts and sheet workers (see below) will see the EP_Cost attribute as the string "@{EffectEP}+@{CTEP}+@{DurationEP}+@{RangeEP}+@{AoEEP}+@{SpecEP}", and will not recognise it as a number. Autocalc attributes are great if you just want to display numbers. If you want to use them in scripts or sheet workers, they are no good. So to convert this into a sheet worker, you'd change your EP_cost input to   <input type="number" name="attr_EP_Cost" value="0" readonly /> and then at the bottom of your html, create a script block like this: <script type="text/worker"> </script> And all sheet workers you create would go between those two script tags. A sheet worker to calculate EP_Cost could look like: on("change:effectep change:ctep change:durationep change:rangeep change:aoeep change:specep sheet:opened", function() {      getAttrs(['EffectEP','CTEP','DurationEP','RangeEP','AoEEP','SpecEP'], function(v) {         const getvalue = (stat) => +stat || 0;         setAttrs({             EP_Cost: getvalue(v.EffectEP) + getvalue(v.CTEP) + getvalue(v.DurationEP) + getvalue(v.RangeEP) + getvalue(v.AoEEP) + getvalue(v.SpecEP)         });     }); }); I encourage you to read up on sheet workers in the wiki, to understand (among other things) why some attributes are capitalised and others arent.  For this to work, all six of the attributes used to build this must not be autocalc. And if they are built from other stats, none of the stats in the chain can be autocalc attributes. You need to build them all with sheet workers.
1572701617
GiGs
Pro
Sheet Author
API Scripter
Once you have that set up, you can simply use the script ChatSetAttr to edit attributes with a macro. No need to make your own script to do it.
Definitely going to need to read up on the sheet workers section. I had some of those other sections being autocalculated too, and I will need to change around the numbers for that as well. Reading up on that should hopefully help with the HP and EP issue that's causing me struggles on another thread.