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

"...unless you use an image that is in your Roll20 Library..."

So in following the documentation, I got the url to the image that I'm trying to add via API, but it still throws this error: "ERROR: You cannot set the imgsrc or avatar of an object unless you use an image that is in your Roll20 Library. See the API documentation for more info." Here's the create section: var curPageId = findObjs({_type: "campaign"})[0].get("playerpageid"); var graphic = createObj('graphic', { name: name, _pageid: curPageId, imgsrc: "<a href="https://s3.amazonaws.com/files.d20.io/images/5356582/kSzAxQqNOBlRlEKPRwKlUg/thumb.png?1409327289" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/5356582/kSzAxQqNOBlRlEKPRwKlUg/thumb.png?1409327289</a>", layer: "objects" }); It must be something stupid, but I can't spot it... I have even re-uploaded the image just to make sure I wasn't smoking crack...
Nevermind, single quotes got it. Score one for desperation... imgsrc: ' <a href="https://s3.amazonaws.com/files.d20.io/images/5356582/kSzAxQqNOBlRlEKPRwKlUg/thumb.png?1409327289" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/5356582/kSzAxQqNOBlRlEKPRwKlUg/thumb.png?1409327289</a> ',
1409328369
The Aaron
Roll20 Production Team
API Scripter
Weird. Double quotes should have worked fine. This probably should be in the API forum. BTW, you don't need to use findObjs() to get the campaign object (and shouldn't because it's more expensive), you can call the Campaign() function. on('ready', function() { var curPageId = Campaign().get("playerpageid"); var imgsrc = '<a href="https://s3.amazonaws.com/files.d20.io/images/5356582/kSzAxQqNOBlRlEKPRwKlUg/thumb.png?1409327289" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/5356582/kSzAxQqNOBlRlEKPRwKlUg/thumb.png?1409327289</a>'; var graphic = createObj('graphic', { name: 'test', pageid: curPageId, imgsrc: imgsrc, layer: "objects", top: 200, left: 200, height: 70, width: 70 }); log('after create image check'); });
1409328560

Edited 1409328591
The Aaron
Roll20 Production Team
API Scripter
Verified that double quotes work fine for me. on('ready', function() { var curPageId = Campaign().get("playerpageid"); var graphic = createObj('graphic', { name: 'test', pageid: curPageId, imgsrc: "<a href="https://s3.amazonaws.com/files.d20.io/images/5356582/kSzAxQqNOBlRlEKPRwKlUg/thumb.png?1409327289" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/5356582/kSzAxQqNOBlRlEKPRwKlUg/thumb.png?1409327289</a>", layer: "objects", top: 200, left: 200, height: 70, width: 70 }); log('after create image check'); }); I never did get the error you stated above, but I did notice that if I didn't specify a width and height, the image was not visible (selectable as a zero size object on the map). Also, you don't need the leading _ on properties (and I think there is a good reason not to use them, but I don't remember what it is). They are there to indicate read only properties in the documentation.
Thanks Aaron. I've already changed course, but I'm saving the snippet for future use. I'll go make my next post in the right forum area.
1409329432
The Aaron
Roll20 Production Team
API Scripter
No Worries!
1409337952
Lithl
Pro
Sheet Author
API Scripter
Aaron said: Also, you don't need the leading _ on properties (and I think there is a good reason not to use them, but I don't remember what it is). They are there to indicate read only properties in the documentation. The API functions will prepend the underscore to the property name if needed*. They will perform the same check whether you supply the underscore or not, so it doesn't affect performance. Personally, I think the code looks cleaner without the underscores floating around on half the property references. * I checked. Almost a year ago there was a bug where you could get the source code for API functions. That bug has since been closed.
1409340630
Gauss
Forum Champion
Moved to the API forum.