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

Trouble with getAttrByName()

I'm trying to nab a defense value from a token like so:     var nDefense = getAttrByName(commands['target_id'], commands['defense']);     log('GOT DEFENSE: ' + nDefense); where commands['target_id'] is passed in from the macro as @{target|token_id} and commands['defense'] is 'dodge' in this case. When I run that code, I get: "Invalid character_id -KB3sv-t1vXFMD_xH-Ux for getAttrByName()" However, I can do:     var target = getObj('graphic', commands['target_id']);     target.set("bar1_value", commands['rank']); and I see the correct value go through to the target token.  What's the deal? Or is there a smarter way to get attributes from a token?
Attributes are tied to characters, not tokens.  You will need to get the character id rather than the token id. Without your script it is hard to understand exactly what you need to do, but it sounds like you want to do something like the following: var target = getObj('graphic', commands['target_id']), character = getObj('character', target.get('represents')); Then from there you can: var nDefense = getAttrByName(character.id, commands['defense']);
Ok, thank you. The token/character dichotomy must be what I was missing. I'll try this out tonight!
1456793104
The Aaron
Roll20 Production Team
API Scripter
(Moved to API) Definitely come back with any questions!
I will. You guys have been a great help so far.