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

Setting barX_link via API

1406778033

Edited 1406778132
I am sure I am missing something simple here, new to coding, new to the API... but I can't seem to set the bar3_link properly via the API. I have the token and setting bar3_value works great. I assume I am supposed to get the id of the attribute that I want to link... so I wrote the following: var obj = findObjs({ _type: "attribute", _characterid: Character.id, name: "HP" }); token.set("bar3_link", obj.id); If I log(obj), I see all of the return values including _id, but if I try to log(obj.id) I get undefined. Not sure what I am doing wrong here.
1406779662
Lithl
Pro
Sheet Author
API Scripter
findObjs returns an array, presumably with one element assuming the character has a single attribute named HP. Use obj[0].id instead.
Thanks Brian! That was it, knew it was something simple that I was overlooking.
So I have a question related again to bar linking... Can you link a bar via the API to an auto calculated field? Obviously you can set this link manually, so I would assume you can, however when I try the following: var bar2 = findObjs({ _type: "attribute", _characterid: Character.id, name: "AC" }); "AC" is the auto-calculated field for Armor Class in Pathfinder. I get the following error from the above code: /home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1 orts, require, module, __filename, __dirname) { function f(a){throw a;}var j=v ^ Error: Firebase.child failed: First argument must be a non-empty string and can't contain ".", "#", "$", "[", or "]". at Error ( ) at Ha (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:12:204) at G.W.H (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:126:213) at TrackedObj._doSave ( Now I saw the note with regards to working with Character Sheets on the Wiki: Note that fields which have auto-calculated values will return the formula rather than the result of the value. You can then pass that formula to sendChat() to use the dice engine to calculate the result for you automatically. Because this is an auto-calculated field I am sure that there are several special characters in the value returned... but I don't think the value itself is used for the bar_link... so not sure what could be wrong. Am I missing something?
1406914041
The Aaron
Roll20 Production Team
API Scripter
Hmm.. I tried to duplicate this problem but couldn't. I'm not using same character sheet though. You might have more luck with the getAttrByName() function, if you're just trying to get the value. If I were doing this, I'd probably drop the name: "AC" and get a whole list for the character, then log each of them and see if AC is in there, possibly by a different name like attr_AC. var bar2 = findObjs({ _type: "attribute", _characterid: Character.id }); _.each(bar2,function(a) { log(a); });
Thanks! This should help me debug this, didn't get time yesterday to do that, hopefully later today!
So following this suggestion, it looks like none of the auto-calculated fields come back using findObjs(). Any field that you fill in seems to come back no problem. Unless I am doing something wrong here it sure seems like findObjs() isn't returning the ID of auto-calculated fields for me.
1407020296
The Aaron
Roll20 Production Team
API Scripter
I tried recently and couldn't find the auto-calculated fields either. You might be able to get values from them via the magic of getAttrByName() since it's read only. ... ...tried it, didn't work for me. =/
I am less concerned about values and it isn't a huge deal, just trying to automate some specific token setup in conjunction with my import script. It does feel a bit like a bug... I would expect that you should be able to get the ID of the autocalculated fields, at least for use with bar linking, since it is obviously possible to do via the UI itself.