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] Just starting to learn the API - need help getting started

Alright, putting in the size and location seems to have done the trick (as you said, it must have been invisible), and the error must be happening somewhere else - though I can't imagine where. The error happens 4 times in a row which is weird (at the moment I'm only creating two monsters, and only one of those is getting a token so at most it should only happen twice I would think). I commented out the token creation part of the script, and the error now happens 3 times. This seems to indicate that the token creation is still accounting for one of the errors. I also don't have imgsrc being set anywhere else - does it pop up this error when you create a character sheet without setting an image? That's the only other thing this script creates aside from attributes and macros. At least the error isn't causing any problems at this point - I'd just prefer the script be error-free. Maybe I can track it down tonight.
1507222036
The Aaron
Pro
API Scripter
Yeah, for creating characters, if you don't specify an avatar, it will give that error because the default value for avatar ('') is not "valid". 
I plugged in an avatar and now it's error free. Woo! Next problem: Can I not set the bar_link to an attribute on token creation?  It looked like I have to do an aSet on the object after it is made from what I've found searching. Also is there no way to add tags to a character via the api?  
1507315787
The Aaron
Pro
API Scripter
There is no access to Tags from the API. Setting link attributes is a bit strange.  It wouldn't surprise me if it doesn't work on character creation.  One thing to be aware of is the differance between linking to an attribute object and linking to a sheet attribute that doesn't have an actual attribute object backing it.  Here's the code I use for setting the links in TokenMod:                         cid=mods.represents || token.get('represents') || '';                         if('' !== cid) {                             delta=findObjs({type: 'attribute', characterid: cid, name: f[0]}, {caseInsensitive: true})[0];                             if(delta) {                                 mods[k]=delta.id;                                 mods[k.split(/_/)[0]+'_value']=delta.get('current');                                 mods[k.split(/_/)[0]+'_max']=delta.get('max');                             } else {                                 mods[k]=`sheetattr_${f[0]}`;                             }                         } I first find the character, if it exists, I set the links.  I start by trying to find the attribute object.  If I find it, I set the bar1_link to its id, then set the bar1_value and bar1_max to the parts of the attribute.  If I don't find the attribute object, I set it to the name of the attribute prefaced by `sheetattr_`. That should make it work, even at creation.  If what you're getting is empty bars, it's because setting to a particular attribute ID with the API does not cause the values to be set initially, so you have to do that manually.  I think I remember that if you move the token or rotate it or some other mutation, they will snap in there, but this avoid that step and makes it work like you would expect it to work.
1507352803

Edited 1507352979
Ok, brain hurting. I'm trying to dig through tokenMod but it is simply more advanced than what I can understand. I'm not certain what f[0] evaluates to. I thought it was the name of the attribute but I tried plugging in my attribute name directly (replacing f[0] with "hp") and it doesn't seem to be working. I'm assuming cid is the character sheet id (in my code sheet.id), but I don't know what 'k' evaluates to either (or for that matter what data mods is holding) - I was assuming 'k' was something like "bar1_link" but I'm not sure that's right since I'm not getting past the "delta=..." line.
I figured out the problem with my delta - it was an order of operations issue. I might be able to get the rest.
1507496932
The Aaron
Pro
API Scripter
Yeah, sorry, should have explained that a bit better.  f[0] is the attribute name to link to. cid is the id of the character.  k does contain the bar to link 'bar1_link' I was just trying to illustrating the process really.
Finally got it all working - it makes the token, links the bars to the attributes, sets the token to be the default token for the monster, then deletes the token. Thanks yet again for the help! Time to put it to the stress test with a whole sheet of monsters and see what breaks...
1507561270
The Aaron
Pro
API Scripter
Cool, no problem!