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

[help/API] How can I set character sheet's attributes with js?

Hi, I am going to make character sheet auto-generator with js. (I referred Cal of Cthulhu 7th sheet) This is my command example(I hope)> !mksh -name=Jimmy -age=18 -luck=3d5*5 -STR=80 -DEX=50 -Sanity=50 -Accounting=5 -Anthropology=1 I want to contain character's infomation and status (like characteristics, HP, Luck, Sanity, Investigator Skills, etc) in command options. I found the way to make new character sheet, but I cannot found the way to set each "attribute" with js. I just set character name, but I didn't know other "attributes". Even I searched this maybe 3 hours, but cannot found the information.... Does anyone know about this one? Please advise me. Thanks.
1613742665
The Aaron
Roll20 Production Team
API Scripter
Attributes are another object type. You create them with createObj() like you create characters. Check this page:&nbsp; <a href="https://help.roll20.net/hc/en-us/articles/360037772793-API-Objects" rel="nofollow">https://help.roll20.net/hc/en-us/articles/360037772793-API-Objects</a>
1613743242
timmaugh
Roll20 Production Team
API Scripter
Hey, Itjeong... here are a couple of places to start (and keep bookmarked): <a href="https://help.roll20.net/hc/en-us/articles/360037772833-API-Function-Documentation#API:FunctionDocumentation-createObj" rel="nofollow">https://help.roll20.net/hc/en-us/articles/360037772833-API-Function-Documentation#API:FunctionDocumentation-createObj</a> <a href="https://help.roll20.net/hc/en-us/articles/360037772793-API-Objects#API:Objects-Attribute" rel="nofollow">https://help.roll20.net/hc/en-us/articles/360037772793-API-Objects#API:Objects-Attribute</a> The first is the actual createObj function that R20 exposes to create the various objects. There are other functions in there, so definitely keep that handy. The second is the documentation of the various sorts of objects you can interact with, specifically linked to the attributes. One thing to remember is that although the attributes belong to a character, they are not attached to the character. They have their own id, and are attached to the character by use of a foreign key (to use database terminology). So if your character has an ID of -M1234567890abcdef, then that character might have attributes that look like: id: -Mfedcapfdsah04n201 type: 'attribute' character_id: -M1234567890abcdef name: 'Anthropology' current: 1 max: 1 // etc. You will need to arrive at the character to work on (so that you know whose attributes to retrieve/work on). You can do that with a selected character, a targeted character, a roll query that asks you for a character, or by generating a new character (the createObj function returns the object you created). Once, you can get the character's_id feed it any function to help get things associated with that character. Obviously, you'll need to check if the character actually exists (creating if not), and then check if each attribute exists (creating if not, updating if so). There's a lot you sort of learn along the way... like what properties can be accessed directly off the object (like id and type) versus what properties must be accessed using the get() function: theAttr.get('current') ...or how to get repeating attributes (attributes in list). There's also a known bug when trying to set properties of an object you created in the same statement that creates it... you should create it, assign it to a variable, then apply the properties. Really, it's too much to list in one post all of the things to know that you might potentially bump into... better if you get started and post back with specific questions. Also, one of the best resources is seeing what other people have already done. Look on the Roll20 GitHub for examples. Steal our stuff. =D More reading: Wiki: Beginning to work with character sheets. Wiki: API Scripts