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

Help with getAttrByName

In my API script I look for an attribute in a character sheet and it is not found I want to use a default value.  The problem is when I call getAttrByName and check the return if null or '' or typeof undefined all of them return false.  What should I test for?
1488836185

Edited 1488836206
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
A snippet would be helpful, but it sounds like you are trying something like this: var attributeCurrent = getAttrByName(character_id,'AttributeName'); Your problem here is that getAttrByName returns the default value for that attribute if it isn't found. The default value for any attribute's current/max value is "". So your attribute var will never be null or undefined. How are you checking for empty string? Personally, I don't know that I've ever used getAttrByName. It has such restrictive requirements for what you have to know to use it, I've always found it easier to just use findObjs and filter, which becomes even more appealing with the recent speed improvements to findObjs thanks to the caching of objects at startup.
That is very simaler and I am if (attributeCurrent == '') which returns false.   I will re write my script to use the findObj and filter. thanks
1488866323
Lithl
Pro
Sheet Author
API Scripter
Are you using a character sheet? getAttrByName is supposed to use the default value of the attribute specified in the character sheet if the attribute hasn't been defined. That default value could potentially be anything.