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]Getting and setting attributes

I've been screwing around with the API in an attempt to set the bar1 of tokens within Dark Heresy 2 (Advanced) to the character's wounds attribute automatically and had absolutely zero luck. on("add:graphic", function(obj) { var objWounds = findObjs({ name: 'Wounds', _type: 'attribute', _characterid: obj.id }, {caseInsensitive: true})[0]; }); Any attempt to call objWounds results in undefined. Any help?
1574480716
GiGs
Pro
Sheet Author
API Scripter
You're getting the id of the graphic there, not the id of a character. Also, you want to be careful that the graphic is a token (and not, say, a map, or some other graphic element), and if it is a token, that it represents a character. You then want to check that the wounds attribute exists and has a valid numeric value (probably the case if it represents a character, but depends on the character sheet in use).
1574481792
GiGs
Pro
Sheet Author
API Scripter
Try something like this (written quickly while making lunch, so havent checked it) on("ready", function() {     on("add:graphic", function(token) {         if(token.get('represents') === '') return;         const character = getObj('character', token.get('represents'));         const wounds = getAttrByName(character.id, 'Wounds');         if(token.get('bar1_link') === '') {             // only assign wounds if the bar isnt already linked to a character sheet             token.set({                 bar1_max: wounds,                 bar1_value: wounds             })         }     }); });
I think that's close enough to bang my head against for a while. Thanks.