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] API On change:attribute does not return a usable object.

1461473101
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
     on("change:attribute", function (attr, oldAttribute) {         'use strict'; log( attr); log( oldAttribute);         var sa = oldAttribute["name"];         var sa1 = attr["name"]; log( sa); log( sa1);    }); results in  {"name":"repeating_skilll_0_SKL_Name","current":"Dwarvish g","max":"","_id":"-K-EGLizfnUmBQ1Kh-Bw","_type":"attribute","_characterid":"-JvAdIYpXgVyt2yd07hv"} {"name":"repeating_skilll_0_SKL_Name","current":"Dwarvish","max":"","_id":"-K-EGLizfnUmBQ1Kh-Bw","_type":"attribute","_characterid":"-JvAdIYpXgVyt2yd07hv"} "repeating_skilll_0_SKL_Name" undefined My understanding is that when the API On Change:attribute fires I will have two objects. One with the new current attribute, and one with the old attribute.  While I can access the oldAttribute, the new attribute, while appearing to show a perfectly good object, always says that "name" is undefined. .
1461483244

Edited 1461483834
Lithl
Pro
Sheet Author
API Scripter
The previous value of an object passed to a change event callback (oldAttribute in this example) is a POJO, and you can access its properties directly. The current value of an object passed to a change event callback (attr in this example) is a Roll20 object, like what you would get from the return value of getObj or findObjs. The only attribute you can access directly is id. All of the rest of the properties can only be accessed with the get and set functions. So, while oldAttribute.name and oldAttribute['name'] both work, you need to use attr.get('name'). ETA: You can actually skip the get call with attr.attributes.name, although if you try to bypass the set call that way, the new values won't save properly. You also can't take advantage of shim properties for statusmarkers.
1461512873
Lithl
Pro
Sheet Author
API Scripter
Hey Chris, this thread gave me the idea to create  this API script . If it loads before yours, your attr parameter in your above code will have direct access to the object's properties in the same was as the oldAttribute parameter.
1461532207
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Thank you much!  I thought I was going crazy.