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

[Script][5e OGL] Question about action creation via API scripts

Hello! I have been working on a script for generating npc 5e OGL sheets but have run into a snag involving abilities and was wondering if someone knew the cause. Up to this point I have been filling in the stats on the sheet by adding attribute objects to the character with the names that the 5e OGL is expecting to find for those values(i.e i make a "npc_name" attribute since i know that is the attribute name the OGL sheet is looking to find for the value of the npc's name). I extended this logic to creating abilities but it doesn't seem to be using my attributes in the way I was hopping it would. So far I have been able to create abilities in the ability list for the monster and fill them with data such as +hit, damage die, range, etc. However when the ability is marked as an attack and I press the ability it does not roll an attack. It does does nothing in fact :( I figured out the source of the issue is that the ability does not have a roll template attribute associated. The name of the roll template attribute seems to follow the format "repeating_npcaction_{ABILITY_ID}_rollbase" and contains the roll template for the attack. I believe, when you make an ability through the sheet GUI it generates this for you and alters it when data changes that would modify how the attack is rolled. My issue is that the sheet does not seem to be generating this for me and modifying the attack does not seem to be creating/modifying it either. does anyone know if there is a way to get the sheet to create and manage these generated attributes properly? It seems a bit tedious and error prone to enter these myself and also means if someone modifies these attacks after the sheet is generated(i.e change an existing melee attack into a ranged one) it will always roll improperly.  I'm wondering if part of the issue is how i am generating the ability id. i see the OGL sheet is generating them using generateRowId() but i do not seem to have access to such API from a script. I have been making my own unique abilitiy id's but i'm not sure if the sheet needs to be aware of these id's to work correctly. If you have any thoughts about what is going on i'd love for more info :) I can pose code if it helps but I figured this is a more of a conceptual understanding of how the OGL 5e sheet creates and manages abilities. 
First thing, make sure you are using  this to generate your IDs. Yes, you do need to add it to your script manually since Roll20 does not open up this function to the API like it does sheet workers. Secondly, make sure that you are using the  setWithWorker function instead of set. This will trigger the sheet workers for the character sheet and ensure the object is set in the same way as if you were to manually enter the values in the character sheet.
Thanks kyle, that worked like a charm :) I wasn't doing either of those which makes sense why things were misbehaving. Out of curiosity, do you know why the unique id is required to be a uuid like what you posted? does repeated sections only take id's of a certain length? or is there something else going on there?
I do not. The Aaron may have a response when he peruses this in the morning. (I see you lurking there)
1512439371
The Aaron
Pro
API Scripter
HAHAHAH.  Sorry, was on PTO today and goofed off by making an update to TokenMod. =D The reason it needs to be a GUID like that is to match the way Roll20 makes them.  (I teased that code out of the Roll20 Javascript, so it's precisely what they use, though the names are different because of minification.) You could  use just about anything you wanted, short of beginning with a $ for the id ($1, $2, etc are special), but you might run into issues.  Stephen Shomo and I experimented with using a fixed ID sequence, and it turns out to do some weird things across multiple character sheets.  The GUIDs from that script are mostly guaranteed not to collide (lowercasing and substituting for - increases the likelihood of a collision, but we're still talking about "less likely than rolling a nat 20 all night at the gaming table"), and since someone thoughtfully wrote out the function for you already, no reason not to use it. =D
Ya that makes sense. I was generating my own initially but i think the my issue was caused by not using setWithWorker for setting the row attributes rather then generating my own id's. it was mostly just a curiosity because but your right, I might as well follow the convention the character sheet follows since the work of making it is already done for me :) and thanks again for the response, both of you :D