libTokenMarkers provides an easy encapsulation around Custom Token Markers. It is a library for other scripts to use and does not have a user interface. It is intended to be a dependency for other scripts. Function Reference libTokenMarkers.getStatus( <arg> ) Argument Value arg string [return] TokenMarker This function will find the first TokenMarker with a tag or name of arg and return it. Matches are case-insensitive. In the case that there is not a matching TokenMarker, it will return an object that behaves like a TokenMarker, but is empty. let status = libTokenMarker.getStatus( 'purple-dino' );
libTokenMarkers.getStatuses( <arg> ) Argument Value arg string [return] array of TokenMarker This function will find all the TokenMarkers with a tag or name of arg and return an array of all of them. Matches are case-insensitive. In the case that there are not any matching TokenMarkers, it will return an empty array. let statuses = libTokenMarker.getStatuses( 'marked' );
libTokenMarkers.getOrderedList( ) Argument Value [return] array of TokenMarker This function will return an array of all TokenMarkers, in the order they appear in the user interface. let allStatuses = libTokenMarker.getOrderedList();
TokenMarker Object Reference All of the functions above return objects in the TokenMarker class hierarchy. This provides a uniform interface to the four different types of status markers you might need to deal with: Text -- the dead status and its red X Color Dot -- the color statuses like blue and pink , and their non-image based visual Legacy Markers -- the basic set like archery-target and drink-me , where the name and tag are the same Custom Token Markers -- the new dynamic statuses with their images, names, and numbered tags The TokenMarker object has 3 functions on it, detailed below. .getName() Argument Value [return] string This function returns the text name that was given to the status when it was created. .getTag() Argument Value [return] string This function returns the text tag that you use for setting it or checking if it is on a token. .getHTML( [scale], [css] ) Argument Value scale (optional) number ( Default: 1.4 ) css (optional) css string [return] HTML string This function returns a formatted HTML string which can be output in chat to display what the status looks like. This is one of the main benefits of the TokenMarker object. The scale parameter can be used to adjust the size of the visual with respect to the text that surrounds it. Generally, you won't need to supply a parameter as the output will be scaled with the text it is associated with: let tm = libTokenMarkers.getStatus( 'blue' );
sendChat( '' , `<p>Blue at nomral size: ${tm.getHTML()} </p>` );
sendChat( '' , `<h1>Blue at title size: ${tm.getHTML()} </h1>` );
Example Script /* global libTokenMarkers */
on( 'ready' , ()=>{
// Make sure libTokenMarkers exists, and has the functions that are expected
if ( 'undefined' === typeof libTokenMarkers
|| ([ 'getStatus' , 'getStatuses' , 'getOrderedList' ].find(k=>
!libTokenMarkers.hasOwnProperty(k) || 'function' !== typeof libTokenMarkers[k]
))
) {
// notify of the missing library
sendChat( '' , `/w gm <div style="color:red;font-weight:bold;border:2px solid red;background-color:black;border-radius:1em;padding:1em;">Missing dependency: libTokenMarkers</div>` );
} else {
// active code
on( 'chat:message' ,(msg) => {
if ( 'api' ===msg.type && /^!test-ltm/i .test(msg.content)){
// get all the statuses
let all = libTokenMarkers.getOrderedList();
let statLast = all[all.length- 1 ];
// get all the statuses named 'green'
let statGreen = libTokenMarkers.getStatuses( 'green' );
// get the first status named 'blue', case-insensitive
let statBlue = libTokenMarkers.getStatus( 'BlUe' );
sendChat( '' , `<div>Found ${all.length} statuses.</div>` );
sendChat( '' , `<div>Last one is named " ${statLast.getName()} " with tag " ${statLast.getTag()} " and looks like ${statLast.getHTML(3)} .</div>` );
sendChat( '' , `<div>There are ${statGreen.length} statuses named green: ${statGreen.map(s=>s.getHTML(1,"border:1px solid green;padding: .1em; border-radius: .3em; margin: .2em;")).join('')} </div>` );
sendChat( '' , `<div>Looked up " ${statBlue.getName()} " with "BlUe", looks like ${statBlue.getHTML(3)} .</div>` );
// trying to get a non-existing status
let nope = libTokenMarkers.getStatus( 'asdfasdfasdfasdf' );
let nopes = libTokenMarkers.getStatuses( 'asdfasdfasdfasdf' );
sendChat( '' , `<div>Looked up "asdfasdfasdfasdf", found name: " ${nope.getName()} ", tag: " ${nope.getTag()} ", image: ${nope.getHTML()} </div>` );
sendChat( '' , `<div>There are ${nopes.length} statuses named "asdfasdfasdfasdf".</div>` );
sendChat( '' , `<div><h3>All Statuses</h3><table style="border:1px solid #999;padding:.2em;"><thead><tr><th style="padding: 1px .1em;">Icon</th><th style="padding: 1px .1em;">Name</th><th style="padding: 1px .1em;">Tag</th></tr></thead><tbody> ${
all.map((s,n)=>`<tr style="background-color:${n%2?'#fff':'#ccc'} "><td style="padding: 1px .1em;"> ${s.getHTML()} </td><td style="padding: 1px .1em;"> ${s.getName()} </td><td style="padding: 1px .1em;"> ${s.getTag()} </td></tr>` ).join( '' )
}< /tbody></ table> </ div > `);
}
});
}
}); Available now on Git: <a href="https://github.com/shdwjk/Roll20API/blob/master/libTokenMarkers/libTokenMarkers.js" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/libTokenMarkers/libTokenMarkers.js</a> But better declared as a dependency in your scripts.json for your 1-click scripts: "dependencies": ["libTokenMarkers"], Support my work on If you use my scripts, want to contribute, and have the spare bucks to do so , go right ahead. However, please don't feel like you must contribute just to use them! I'd much rather have happy Roll20 users armed with my scripts than people not using them out of some sense of shame. Use them and be happy, completely guilt-free! Disclaimer: This Patreon campaign is not affiliated with Roll20; as such, contributions are voluntary and Roll20 cannot provide support or refunds for contributions.