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 D&D Next character sheet

1403024677

Edited 1403024754
I have a macro set up that passes the selectedID and targetedID to an API function. I get the following: var vAttacker = getAttrByName(vAttackerID, 'character_name'); - Results in: For reference, the error message generated was: SyntaxError: Expected "(", ".", "[", "abs(", "ceil(", "d", "floor(", "round(", "t", "{", [ |\t], [+|\-] or [0-9] but "u" found. var vAttacker = getAttrByName(vAttackerID, 'character_name', " "); - Results in an unidentified result. -Also get this error message: "Invalid character_id -JP2WmXTbLd1tBFEEYDv for getAttrByName()" I feel I must be brain farting here somewhere....lol
1403026521
Chad
Sheet Author
We're going to need your whole script I think. Or at least more than that. There is something wrong with the ID you are sending. At a guess, I think you are passing an ID of a different type, but I'd have to see it all to tell you. The other error could be related or a typo in a line above.
1403027462
Lithl
Pro
Sheet Author
API Scripter
You can't pass both selectedId and targetId in a macro, because choosing a target will deselect whatever token you have selected. The third parameter to getAttrByName should be "current" or "max" (or omit the third parameter entirely to get "current"), not a space.
Ok, here is the code from <a href="https://wiki.roll20.net/Character_Sheets" rel="nofollow">https://wiki.roll20.net/Character_Sheets</a> that says you can use this from within the API to get the various aspects of the new character sheets. getAttrByName(character_id, attribute_name, value_type); Does it require an object for the character to be created?
1403043301
Lithl
Pro
Sheet Author
API Scripter
I'm not sure I understand your question. In order to use the getAttrByName function, you need a character's id string (it will be something along the lines of "-Abc123"), the name of the attribute, and -- optionally -- whether you want the max for the attribute. The simplest way to get the character id is to get the character object from one of the object-finding functions (findObjs, filterObjs, etc.). Given a variable character which represents a character object, the character's id string is character.id If you want the current value of the attribute named "my-attribute", you would then call getAttrByName(character.id, "my-attribute"); and you're set. If the character's attribute hasn't been set yet, the API will pull the default value from the character sheet, whatever it may be (defined by the character sheet author). If, however, you need the maximum value of the attribute, you have to supply the third parameter: getAttrByName(character.id, "my-attribute", "max"); Again, you'll get the character sheet default value if the attribute doesn't exist yet.
Ok, i think I see the issue. I was using @{selected|token_id} in a macro and passing it too the API. I then populated the ID as a variable and was trying to use the ID to populate the character.id. Seems that was too easy....lol
1403044689
Lithl
Pro
Sheet Author
API Scripter
Yes, token_id would be incorrect (it's the id of a graphic object, not a character object). However, you could get the character from that ( var character = getObj('character', getObj('graphic', selectedId).get('represents')); for example). I believe you can also do @{selected|character_id} in your macro, but I'm not 100% on that one.
Thanks Brian, that was the code I needed. I can now pass the character ID for the selected character and the character ID for the target character and retrieve attributes from both.