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

ERROR: You cannot set the imgsrc or avatar of an object unless you use an image that is in your Roll20 Library.

I'm new to this whole java scripting thing and I've run into what seems like a simple and common problem. Why am I getting this error? I've been at it for hours and nothing works. I'm following a tutorial to make a basic script, but I keep getting this same "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." The image IS IN MY LIBRARY!! and all characters have an avatar image. Just to be clear, I tried using an image that I created in photoshop and uploaded directly to My Images, but I still get this error. Here's the script... on ("chat:message",function(msg){ &nbsp; &nbsp; if(msg.type=="api"&amp;&amp; msg.content.indexOf("!spiritualWeapon")==0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var selected = msg.selected; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (selected===undefined) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("API","Please select a character."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var tok = getObj("graphic",selected[0]._id); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createObj("graphic",{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left:tok.get("left")+70, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top:tok.get("top"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height:70, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:70, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageid:tok.get("pageid"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer:"objects", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imgsrc: "<a href="https://files.d20.io/images/364601650/-x89vpob6Iu5OWQUHNQKeQ/thumb.png?16981002045" rel="nofollow">https://files.d20.io/images/364601650/-x89vpob6Iu5OWQUHNQKeQ/thumb.png?16981002045</a>" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat(tok.get("name"),"summoned Spiritual Weapon") &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp;&nbsp; });
1698114616

Edited 1698114908
GiGs
Pro
Sheet Author
API Scripter
That message is usually because you are trying to access something bought from the marketplace. (Edit: I didn't see you were using your own image. Skip to the end.) Unfortunately, scripts can't do anything with marketplace images, even if they are in your library, to cut down on software piracy. Any images have to be actually in your library: If you have any marketplace images, you'll need to download them and reupload them into your library. You can't do this with all marketplace images and you're out of luck with those. But for those you can, download and reupload. Your own Image If this is happening with an image of your own creation, I can only guess, but my guess is that there is something about that image that stops Roll20 recognising it as an image. Try this: pick any other image - a temporary placeholder. Add that to your library, and see if it works. If so, there's something up with your image. Also, load your image in a different program than photoshop and save it as a different format (if it's currently a jpg, save as png, or vice-versa) and try with that. this forces the image file to be recreated, and whatever is stopping it work might be cleared. Also, you could try changing its format in photoshop. Also, make sure you are using a format that Roll20 supports (like jpg or png).
1698114995

Edited 1698115067
GiGs
Pro
Sheet Author
API Scripter
Also, shiouldn't this line var selected = msg.selected; be var selected = msg.selected[0]; ? Never mind, I see you recognise it as an array later.
1698120622

Edited 1698120649
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Several things to try: 1) delete the cache buster: <a href="https://files.d20.io/images/364601650/-x89vpob6Iu5OWQUHNQKeQ/thumb.png" rel="nofollow">https://files.d20.io/images/364601650/-x89vpob6Iu5OWQUHNQKeQ/thumb.png</a> 2) try forcing the browser to see it as a jpg (it will still display as a png): <a href="https://files.d20.io/images/364601650/-x89vpob6Iu5OWQUHNQKeQ/thumb.png.jpg" rel="nofollow">https://files.d20.io/images/364601650/-x89vpob6Iu5OWQUHNQKeQ/thumb.png.jpg</a> 3) Some issues have been observed with the domain. Try: <a href="https://s3.amazonaws.com/files.d20.io/images/364601650/-x89vpob6Iu5OWQUHNQKeQ/thumb.png" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/364601650/-x89vpob6Iu5OWQUHNQKeQ/thumb.png</a>
1698120869

Edited 1698121024
So this was brought up recently in a post by The Aaron , that the API still deals with the S3 URLs and not the files.d20.io addresses. I tested this with my own image and&nbsp; Nick Olivo's Spiritual Weapon script . I got the same error you got with just using the files.d20.io but once I changed <a href="https://files.d20.io" rel="nofollow">https://files.d20.io</a> &nbsp;to&nbsp; <a href="https://s3.amazonaws.com/files.d20.io" rel="nofollow">https://s3.amazonaws.com/files.d20.io</a> , the script worked as expected. EDIT: I see Keith already beat me to this suggestion. I missed that when I started posting.
WE HAVE A WINNER!!! Congratulations keithcurtis and Joshua N. ! You win the prize for "most helpful people on the internet". I tried everything all of you suggested, and i thank all of you for helping me. Your super fast responses and willingness to help some rando in the forums is commendable. The correct answer to this riddle is to change&nbsp; <a href="https://files.d20.io" rel="nofollow">https://files.d20.io</a> &nbsp;to &nbsp; <a href="https://s3.amazonaws.com/files.d20.io" rel="nofollow">https://s3.amazonaws.com/files.d20.io</a> &nbsp;. &nbsp;Deleting the "cache buster" results in a different error telling you to put it back. Forcing the browser to see a jpeg results in the same "can not set the imgsrc" error. I'll leave a link to this post in the comments of the tutorial I was using on YouTube so others can solve this problem without pulling out all their hair. :D