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

getAttrByName() is not behaving as documented when value is a dropdown list. Is displaying an error message when operating on a value in a repeating section.

1467641765
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
The API objects wiki page says getAttrByName() Gets the value of an attribute, using the default value from the character sheet if the attribute is not present.  This only seems to be behaving reliably when type is a number, and is NOT in a repeating section.  Specifically, if you have  Age: <input name="attr_Age" type="number" value="21" > And you don't change Age, it will return a 21. If you do change Age it will correctly return the value changed to. This is the only case I have found where getAttrByName() works as advertised. If you have a dropdown list such as         <select name="attr_Questor" style="width:9em;">             <option value="0"  title="None."> None</option>             <option value="1"          title="Love, Arts, Music.">Astendar </option>             <option value="11"         title="Building, Construction, Planning.">Upandal </option>             <option value="12" selected         title="Manipulation, Deceit.">Vestrial (Mad) </option>             <option value="13"         title="(Optional)">Death </option>         </select> Then if the user has set a value, the value will be returned. Otherwise (if it is still showing the default value) getAttrByName() returns an empty string (""); Things are different (worse) if you are attempting to display something within a repeating section.  log( getAttrByName( cID, "repeating_discipline_-KLq7eIGgjhop-ZQIjTY_Discipline-Name")); log( getAttrByName( cID, "repeating_discipline_-KLq7eIGgjhop-ZQIjTY_Age3")); displays fine if the values (in the case above a select statement and a number) have been changed from their default values. If they have not then in both cases the console log shows an error message similar to the following.  "Error: No attribute or sheet field found for character_id -KLq7_XpU43TB22AFc9g named repeating_discipline_-KLq7eIGgjhop-ZQIjTY_Age3" and the log shows that getAttrByName is returning a value of undefined. So once again the documentation says it returns the default value. That only happens when type is number and it is not in a repeating section.  For select statements not in a repeating section it returns an empty string.  For numbers or select statements inside a repeating section it displays an error in the console log and returns undefined. 
1467641942
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Rereading the title I realized I should not say that it is "throwing errors". It is not. It is simply displaying an error message in the console log, but execution resumes with a return of an undefined value. That is not "Throwing an error". 
1467652953

Edited 1467652970
Chris D. said: Rereading the title I realized I should not say that it is "throwing errors". It is not. It is simply displaying an error message in the console log, but execution resumes with a return of an undefined value. That is not "Throwing an error".  No worries; I altered the title accordingly.
1467757916
Phil B.
Forum Champion
Sheet Author
I've tested and confirmed this is not working as intended, and one of us will take a look at it when we get a chance.