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

[Request] API Request

1477158383
Pktome
Pro
Sheet Author
I can use the GM Notes of tokens as a source of "attribute"? Let's say in my file has a text area where I type the text with bold, space, etc., and use another macro to play that text in the chat. I could make some API caught text GM Notes Token and played on the screen? My NPCs have no record player it is much more than the enemy character, and the ridiculous amount of chips you need to create, so I would play the necessary information right on GM Notes of Tokens.
1477165554
The Aaron
Pro
API Scripter
I'm not completely clear on what you're asking for.   Are you saying you want to have tokens with their GM Notes full of some information which you want to treat and access as attributes? (not possible with the API) Are you saying you want to have a way to take the text in the GM Notes of a token and display it in the chat? (Trivially easy with the API) Or something else?
1477169726
Pktome
Pro
Sheet Author
Hi, your question was also confused, but let me try to clarify things: I want to pull the GM Note through some command like an attribute. Say the attribute would be selected @{selected|gmnote} and in gmnote put something like ** this is the example test ** Then the chat type: /em something here @{selected|gmnote} (or !gmnote) to leave something like: (GM) something here  this is the example test
1477172370
Lithl
Pro
Sheet Author
API Scripter
The @{selected} syntax wouldn't be possible, but some other syntax could be created and parsed by the API.
1477175945
The Aaron
Pro
API Scripter
As Brian said.  @{selected} and the like are expanded on the client.  So when you type those in chat, your browser has code that replaces them with the value when you hit enter.  The API, on the other hand, operates on a server far removed from your client.  The API cannot affect the way UI elements like @{selected} are expanded. Depending on what you are using your bars for on the token, you could put that text you have in the GMNotes in the max part of a bar and access it with @{selected|bar3|max} or some such.  Additionally, an API script could detect when you edit GMNotes on a token and set that bar's max value to the contents of the GMNotes, giving the illusion that you are accessing the GMNotes.
1477176568
Tetsuo
Forum Champion
Doesn't the "It's a trap" script pull info from the GM Notes of a token? Couldn't you do something similiar to that?
1477178522
The Aaron
Pro
API Scripter
Certainly, but you couldn't access it with an attribute syntax. 
1477178774
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Franky H. said: Doesn't the "It's a trap" script pull info from the GM Notes of a token? Couldn't you do something similiar to that? Yeah, but it's all stored as JSON, which is then parsed so that the script can use those extra "attributes".
1477235983
Pktome
Pro
Sheet Author
Stephen L. said: Franky H. said: Doesn't the "It's a trap" script pull info from the GM Notes of a token? Couldn't you do something similiar to that? Yeah, but it's all stored as JSON, which is then parsed so that the script can use those extra "attributes". Then, a script could pull the text directly without the need of an attribute? Using, for example, !gmnote. Following is the photo of the tokens that I'm using. To put a suggestion: for each token had at least three specific attributes beyond their own bars. So we could conclude that they had Bar1, Bar2, Bar3, Aura1, Aura2, New1, New2 and New3. News These could be, for example, catch phrases they might be talking at random. There is this script that I use to send message to the chat every time someone enters the room - motd Note - he would have what I need?
1477237621
The Aaron
Pro
API Scripter
MotD takes its information from a handout, not a token, but it's a similar concept. If I could understand exactly what you want, I think it would be a pretty simple script, but I think there's a language barrier here.
1477245214
Pktome
Pro
Sheet Author
The Aaron said: MotD takes its information from a handout, not a token, but it's a similar concept. If I could understand exactly what you want, I think it would be a pretty simple script, but I think there's a language barrier here. I want a script that, when typing '! gm note 'anywhere in the chat or even being brought by some attribute, pull the GM Note information. Same Mod Note even if there is through the handout.
1477271098
The Aaron
Pro
API Scripter
Ok.  Try this: on('ready',function(){     'use strict';     on('chat:message',function(msg){         if('api' === msg.type && msg.content.match(/^!gmnote/) && playerIsGM(msg.playerid) ){             _.chain(msg.selected)             .map( s => getObj('graphic',s._id))             .reject(_.isUndefined)             .each( o => {                 sendChat(o.get('name'),decodeURIComponent(o.get('gmnotes')));             });         } }); }); Select a token and execute: !gmnote If that token has a GM Note, it will be sent to the chat with the sender as the selected token's name.
1477271328

Edited 1477271708
Tetsuo
Forum Champion
Could this be configured to search the GMnote for specific lines of text and only display that? ex: !gmnote-poison would find the poison line and display DC20 vs fort or 1d2 con drain 6 rnds.  Admittedly, this is probably stretching the capabilities. 
1477273292
The Aaron
Pro
API Scripter
It could. :)
1477274048
Tetsuo
Forum Champion
And how could that be configured, oh mighty scriptomancer?
1477366026

Edited 1477399531
The Aaron
Pro
API Scripter
Something like this: on('ready',function(){     'use strict';     on('chat:message',function(msg){         if('api' === msg.type && msg.content.match(/^!gmnote/) && playerIsGM(msg.playerid) ){             let match=msg.content.match(/^!gmnote-(.*)$/),                 regex;             if(match && match[1]){                 regex = new RegExp(`^${match[1]}`,'i');             }                                              _.chain(msg.selected)                 .map( s => getObj('graphic',s._id))                 .reject(_.isUndefined)                 .reject((o)=>o.get('gmnotes').length===0)                 .each( o => {                     if(regex){                         let lines=_.filter(decodeURIComponent(o.get('gmnotes')).split(/(?:[\n\r]+|<br\/?>)/),(l)=>regex.test(l)).join('\r');                         sendChat(o.get('name'),lines);                     } else {                         sendChat(o.get('name'),decodeURIComponent(o.get('gmnotes')));                     }                 });         }     }); }); !gmnote-<something> Will output all the lines starting with <something> !gmnote-poison Outputs all the lines that start with poison (case insensitive).  Note that formatting will change what "start with" means.
1477366434
Tetsuo
Forum Champion
Aaron, sometimes I wonder if you realize how truly astonishing your knowledge and talent for this stuff is. 
1477373874
The Aaron
Pro
API Scripter
It's a burden yes, but one that I can live with. =D
1477399564
The Aaron
Pro
API Scripter
Slight edit the the above.. took out some debugging code. =D
1477482752
Pktome
Pro
Sheet Author
thx, I'll try.