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

Read Image URL, Notes and GMNotes from a Handout

Ok, my google-fu is failing me at the moment :( I am looking for a method to read the Notes and GMNotes from a handout. I have found how to create a handout and populate the fields, but not how to read the fields. My use case is this... I have purchased the C&C Monsters and Treasure Compendium, but everything is a handout and you can't drag/drop to the map, makes me sad... So, I have some scripts I made already that had embedded JSON that I formatted in Excel, these would make a character sheet then enter the appropriate data into it's attributes and notes. What I want to do now is similar, but different ;) I would have a game setup that I would open/save the handout from the compendium which will put it into the journal, then run a script reading the Notes so I can create the character sheet entry for it, and finally I can transmogrify them as needed to an active game. I want to run a script on these handouts to extract the data and build the character sheet with that. Simple, except... how the heck do I read the Notes of the handout??? One other thing I would want to do is to get the URL of the image and load it to the character sheet portrait. Then, I still don't think there is a way in the API to load images from URL into the library, please correct me if I am wrong, so it will let me make a list of images to download, then I can add to a library from there manually. Thanks in advance!
1689811768
The Aaron
Roll20 Production Team
API Scripter
You have to use the callback form of .get(). See here:&nbsp; <a href="https://wiki.roll20.net/API:Objects#Using_the_Notes.2C_GMNotes.2C_and_Bio_fields_.5BAsynchronous.5D" rel="nofollow">https://wiki.roll20.net/API:Objects#Using_the_Notes.2C_GMNotes.2C_and_Bio_fields_.5BAsynchronous.5D</a>
Now how the heck did I overlook that one??? Thanks Aaron, as usual you are a rockstar!
1689866495
The Aaron
Roll20 Production Team
API Scripter
Well, it's easy to miss, to be sure.&nbsp; If you need some examples for Notes and GMNotes, take a look at MotD. On the images side, there's not an easy way to move marketplace images into a user library automatically.&nbsp; If you want to detect usable images in an API script, you can pass them through this function: const getCleanImgsrc = (imgsrc) =&gt; { let parts = (imgsrc||'').match(/(.*\/images\/.*)(thumb|med|original|max)([^?]*)(\?[^?]+)?$/); if(parts) { return parts[1]+'thumb'+parts[3]+(parts[4]?parts[4]:`?${Math.round(Math.random()*9999999)}`); } return; }; It will also convert them to the form that the API can created (must be the thumb link);
1689868261
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I'll also note that you can use promises and async/await to avoid callback hell with it: /** * Gets the blob info from roll20 objects asynchronously * @param {string} prop - the property to get * @param {Roll20 Object} obj - the Roll20 object to get the prop from * @returns {Promise&lt;string&gt;} - The contents of the blob. */ const getNotes = function (prop,obj) { return new Promise((resolve, reject) =&gt; { obj.get(prop, (p) =&gt; { resolve(p); }); }); }; Which would be used like so: /** * Sends a character's bio section to chat * @param {R20Object} r20Character - The roll20 character object */ const bioToChat = async (r20Character) =&gt; { const bio = await getNotes('bio',r20Character); sendChat('note output',bio); } In this simple example, it doesn't seem like it saves you much coding, but imagine you want to do manipulation of that bio after you get it (or maybe you want to conditionally get the bio or the gmnotes) and continue writing code in your existing function flow. Doing that with a callback is a PITA. Here, we keep writing the code as if it's synchronous.