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

createObj error

Hi, I'm new to scripting thing, and I hope someone can help me figure this. On the Main server, I have this simple script that create a character: on("chat:message", function(msg) { // Exit if not an api command if (msg.type != "api") return; if (msg.content == '!do') { createCharacter('test'); } }); function createCharacter(name) { obj = findObjs({_type: "character", name: 'test'}); if(obj.length > 0){ return -1; } obj = createObj('character', { name: name, gmnotes: "note" }); log(obj); } Here's the result from API output console: Spinning up new sandbox... "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." {"name":"test","bio":"","gmnotes":"note","archived":false,"inplayerjournals":"","controlledby":"","_id":"-Jgbsa4TshJFZbybyQVz","_type":"character","avatar":""} My question are 1- Why I got the error about set the imgsrc or avatar since I don't set those. 2- Why the gmnote on the newly created character do not contain any gmnote? Thank you.
1422305302
The Aaron
Pro
API Scripter
1) Background: You can only set imgsrc to URLs that refer to images in a User's Library. It can be any user, but it cannot refer to an image in the Market place. Additionally, it needs to be the thumb version of the url. In your case, you're getting it because the imgsrc is being set to something that isn't in a user library: '' It's probably a bug in the validation code, and I have it on a list of similar things already. It doesn't hurt you in this case and you can ignore it. 2) GMNotes, Bios, Notes, all are dealt with asynchronously. ( See: <a href="https://wiki.roll20.net/API:Objects#Using_the_Note" rel="nofollow">https://wiki.roll20.net/API:Objects#Using_the_Note</a>... ) For getting, that makes the process completely different. Generally, I have the best luck setting them separately from the create. In your case, it looks like it is working to set them. Here's your logged object, with the value of gmnotes bolded: {"name":"test","bio":"","gmnotes":" note ","archived":false,"inplayerjournals":"","controlledby":"","_id":"-Jgbsa4TshJFZbybyQVz","_type":"character","avatar":""} Note : In Production, there is a bug with created objects such that trying to set values on them will crash the API. Riley has a fix for this on Dev, so it should be coming soon. In the interim, there is a work around to fix the object. You can add this function and use it in place of createObj: var fixedCreateObj = fixedCreateObj || function () { var obj = createObj.apply(this, arguments); if (obj && !obj.fbpath) { obj.fbpath = obj.changed._fbpath.replace(/([^\/]*\/){4}/, "/"); } return obj; };
1422305339
The Aaron
Pro
API Scripter
Also, you can format a block of text as code by selecting it and clicking on the paragraph symbol at the upper left of the edit window, and choosing code.
Thank you. So to conclude, those are nothing to do with my code.
1422336026
The Aaron
Pro
API Scripter
Well, the 1st one is a side effect of not setting an imgsrc, and the 2nd one isn't actually happening, so I guess yes? =D