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

Token GMnotes

1626158871

Edited 1626159728
Ivo
Pro
I'm using a script that Aaron created to add notes to a tokens GMnotes, then use the new scriptcards api to create an array from them and spit them out nice and formatted to chat. The problem I get is that until I go into the token and hit the save button(after adding text with the add-gmnote api), the gmnotes section behaves in a whacky fashion. As soon as you save the token, it all works fine, until then there are some weird formatting characters that I cant see or get rid off. Is there a way to force a save on the token from the API? I do a few string replacements to get rid of formatting characters, but even when I dump the string into the log, its not showing these cntl characters at all, unlike the other ones, even the log skips out of the formatted dump section. Before & after a  save (From GM (GM)): Token Notes L  Some line 1 L  Some line 2 L  Some line 3 L L  Testing the note L  12345 thing GM (GM): Oby its raining x xxxx xxx From GM (GM)): Token Notes L  Some line 1 L  Some line 2 L  Some line 3 L L  Testing the note L  12345 thing L  Oby its raining L  x L  xxxx xxx
1626181285
The Aaron
Roll20 Production Team
API Scripter
I can probably fix that.  Which note script are you using?
1626185728

Edited 1626185767
Ivo
Pro
This one from an old forum, then using scriptcards string & array functions to format it on('ready',function(){     'use strict';     const cmdregex=/^(!(?:set|add)-(?:c?gmnote|bio))\s*/,         formatMsg = (c)=>c.replace(cmdregex,'').replace(/(^{{\s*|\s*}}$)/gm,'');     on('chat:message',function(msg){         if('api' === msg.type) {             let match=msg.content.match(cmdregex);             if(match && playerIsGM(msg.playerid) ){                 let content = formatMsg(msg.content),                     who=(getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname');                 if(_.has(msg,'inlinerolls')){                     content = _.chain(msg.inlinerolls)                         .reduce(function(m,v,k){                             var ti=_.reduce(v.results.rolls,function(m2,v2){                                 if(_.has(v2,'table')){                                     m2.push(_.reduce(v2.results,function(m3,v3){                                         m3.push(v3.tableItem.name);                                         return m3;                                     },[]).join(', '));                                 }                                 return m2;                             },[]).join(', ');                             m['$[['+k+']]']= (ti.length && ti) || v.results.total || 0;                             return m;                         },{})                         .reduce(function(m,v,k){                             return m.replace(k,v);                         },content)                         .value();                 }                 if(content.length){                     let tokens = _.chain(msg.selected)                         .map( s => getObj('graphic',s._id))                         .reject(_.isUndefined)                         ;                     switch(match[1]){                         case '!set-gmnote':                             tokens.each( o => {                                 o.set({                                     gmnotes: content                                 });                             });                             break;                         case '!set-cgmnote':                             tokens.map( o => getObj('character',o.get('represents')))                                 .reject(_.isUndefined)                                 .each( o => {                                     o.set({                                         gmnotes: content                                     });                                 });                             break;                                                      case '!set-bio':                             tokens.map( o => getObj('character',o.get('represents')))                                 .reject(_.isUndefined)                                 .each( o => {                                     o.set({                                         bio: content                                     });                                 });                             break;                         case '!add-gmnote':                             tokens.each( o =>{                                 o.set({                                     gmnotes: `${o.get('gmnotes')}<br>\n${content}`                                 });                             });                             break;                         case '!add-cgmnote':                             tokens.map( o => getObj('character',o.get('represents')))                                 .reject(_.isUndefined)                                 .each( o => {                                     o.get('gmnotes',(notes)=>{                                         _.defer(()=>o.set({                                             gmnotes: `${notes}<br>\n${content}`                                         }));                                     });                                 });                             break;                         case '!add-bio':                             tokens.map( o => getObj('character',o.get('represents')))                                 .reject(_.isUndefined)                                 .each( o => {                                     o.get('bio',(notes)=>{                                         _.defer(()=>o.set({                                             bio: `${notes}<br>\n${content}`                                         }));                                     });                                 });                             break;                     }                 } else {                     sendChat('',`/w "${who}" <div>`+                         `<div>Use <code>COMMNAD Some Text</code> or <code>COMMAND {{ some multi-line text}}</code>.</div>`+                         `<div><b>Commands:</b></div>`+                         `<div><ul>`+                             `<li><code>!set-gmnote</code> -- Replaces contents of token gmnotes.</li>`+                             `<li><code>!set-cgmnote</code> -- Replaces contents of character gmnotes.</li>`+                             `<li><code>!set-bio</code> -- Replaces contents of character bio.</li>`+                             `<li><code>!add-gmnote</code> -- Appends to contents of token gmnotes.</li>`+                             `<li><code>!add-cgmnote</code> -- Appends to contents of character gmnotes.</li>`+                             `<li><code>!add-bio</code> -- Appends to contents of character bio.</li>`+                         `</ul></div>`                     );                 }             }         }     }); });