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] Updating an Ability

1464907292
Finderski
Pro
Sheet Author
Compendium Curator
Ok, I've run into another problem... I'm trying to update an Ability, and I thought I knew how to do it, but...apparently not. Here's my code: on("change:attribute", function(obj){     var aName = obj.get('name'), cID = obj.get('characterid'), aValue = obj.get('current'); log("aName: " + aName); if (aName == 'is_npc' && aValue == '1') { log("### Character Sheet Type Changed ###"); log("### Need to update Token Actions ###"); var updateAgility = findObjs({ _type: "ability", _characterid: cID, name: "Agility"}); log(updateAgility);         updateAgility.set({action: "@{skillrt} @{defsTemplate} @{rolltmAgility}"}); } }); From what I've seen in other scripts, I thought it was the .set that would update the ability, but I keep getting an error message: TypeError: updateAgility.set is not a function at apiscript.js:1343:23 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:105:34), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:105:34), <anonymous>:70:8) at TrackedObj.set (/home/node/d20-api-server/api.js:704:14) at updateLocalCache (/home/node/d20-api-server/api.js:933:18) at /home/node/d20-api-server/api.js:1076:11 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546) at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489) at Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425) So...what am I doing wrong on this one? I've seen in the documentation that I can create an object and remove an object, but there doesn't seem to be an update function, but I've seen in other scripts that this seems to be possible, but...I'm missing something.
1464908546

Edited 1464908560
The Aaron
Pro
API Scripter
findObjs() returns an array, not an object.  I can't count the number of times this has bit me. =D on("change:attribute", function(obj){     var aName = obj.get('name'), cID = obj.get('characterid'), aValue = obj.get('current'); log("aName: " + aName); if (aName == 'is_npc' && aValue == '1') { log("### Character Sheet Type Changed ###"); log("### Need to update Token Actions ###"); var updateAgility = findObjs({ _type: "ability", _characterid: cID, name: "Agility"}) [0] ; if(updateAgility){ log(updateAgility);         updateAgility.set({action: "@{skillrt} @{defsTemplate} @{rolltmAgility}"}); } } });
1464915895
Finderski
Pro
Sheet Author
Compendium Curator
The Aaron said: findObjs() returns an array, not an object.  I can't count the number of times this has bit me. =D Awesome...I was about to ask how do I extract the information I need, BUT...I looked at the array, and it's actually an array of an object. So, I tried:  var aID = updateAgility[0].set({action: "@{skillrt} @{defsTemplate} @{rolltmAgility}"}); AND IT WORKED!! My last question is regarding the events it watches for...I want it to look for an add or a change, but I can't seem to put them both in the same call like I can with sheet workers.  When I have it formatted like this: on("add: attribute change:attribute", function(obj){ ...stuff goes here... } It's completely ignored and nothing happens when it's an add or a change. But as soon as I do one or the other, voila! it works.  Is there a different way I'm supposed to format that bit? Thanks for all your help.
1464923848
Lithl
Pro
Sheet Author
API Scripter
No, API events can't be grouped like sheet workers. What you can do, however, is factor out the callback function: function addOrChangeAttribute(obj) { ... } on('add:attribute', addOrChangeAttribute); on('change:attribute', addOrChangeAttribute);
1464925267
Finderski
Pro
Sheet Author
Compendium Curator
Brian said: No, API events can't be grouped like sheet workers. What you can do, however, is factor out the callback function: Excellent. Thanks. I now have a functioning API script...ugly, but it works. :)