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

[Bug]getAttrByName won't get the default value of an attr set via select

$subject. If you attempt to use getAttrByName on an attr represented by a select, on the character sheet, it will simply give an empty string back. If you set the attr manually from the character sheet it will then be able to get the value.

Edited 1420041486
What are you trying to do exactly, it could be that you're using the syntax wrong. If you could provide some code it would be good.
Sheet Author
API Scripter
Jacob, I'm pretty sure Matt is reporting this based on your 4e defense script thread.
Ye it looked similar to my problem I just wanted to check.
It would be helpful to get a full test-case of this so I can fix it. For example, just to be sure, the <select> in question has the first option (assumed to be the default) that has a value? Or is the default option one designated by the "selected=true" attribute on a non-first-child option element? That sort of thing. There may be multiple things at play here that need to be taken into account. So if you can paste the section of the character sheet template causing the issue along with your specific JS code where you're seeing this that would be helpful.

Edited 1420053781
this is the issue i encountered which i think is the same problem if not just say Matt var test = getAttrByName(targetCharacter, "ac"); log(test); //"@{ac-ten}+@{ac-ability}+@{ac-armor}+@{ac-class}+@{ac-feat}+@{ac-enh}+@{ac-misc}+@{ac-misc2}" test = getAttrByName(targetCharacter, "ac-ability"); og(test); //"@{ac-highest}" test = getAttrByName(targetCharacter, "ac-highest"); log(test); //"" test = getAttrByName(targetCharacter, "ac-ten"); log(test); //"10+@{halflevel}" test = getAttrByName(targetCharacter, "halflevel"); log(test); //"floor(@{level}/2)" test = getAttrByName(targetCharacter, "level"); log(test); //"5" As you can see "ac-highest" is the only one thing that retuns a null value irelevent of its cotent

Edited 1420057249
Sheet Author
API Scripter
The sheet in question defines ac-highest as: <select name="attr_ac-highest"> <option value="@{strength-mod}">Strength</option> <option value="@{constitution-mod}">Constitution</option> <option value="@{dexterity-mod}" selected="selected">Dexterity</option> <option value="@{intelligence-mod}">Intelligence</option> <option value="@{wisdom-mod}">Wisdom</option> <option value="@{charisma-mod}">Charisma</option> </select> Each of the attribute mods used as a value in the above options are defined as: <input type="text" name="attr_dexterity-mod" value="floor((@{dexterity}-10)/2)" disabled = "true"/> While the attribute itself is: <input type="text" name="attr_dexterity" value="10"/> Going from Jacob's thread in the API forum getAttrByName for ac-highest continues to return an empty string even if you change the selected value.
I wonder what happens if the select has a regular value instead of a formula. Like if <option value="10">. Interesting. Well I should have enough to start testing things now, thanks.
Sorry have been afk for a while. Here is a simple reproduction: Character sheet: <input type="text" name="attr_test"> <select name="attr_binding_diff"> <option value="2">2.0 - Very Easy</option> <option value="1.5">1.5 - Easy</option> <option value="1" selected>1.0 - Standard</option> <option value=".666667">.67 - Hard</option> <option value=".5">.50 - Formidable</option> <option value=".1">.10 - Herculean</option> </select> API Script: on("add:attribute", function(obj) { var attributeName = obj.get("name"); if (attributeName == "test") { var bindingDiffPreParse = getAttrByName(obj.get('_characterid'), "binding_diff"); var bindingDiff = parseFloat(bindingDiffPreParse); log(bindingDiffPreParse); log(bindingDiff) } }); Process: Simply create a new character and put a value into the test input field to trigger the API script. Log output: Spinning up new sandbox... "" null "" null