Here are some functions I've written for dealing with status markers / token markers: const unpackSM = (stats) => stats.split(/,/).reduce((m,v) => {
let p = v.split(/@/);
let n = (undefined === p[1] ? true : parseInt(p[1] || '0', 10));
if(p[0].length) {
m[p[0]] = n;
}
return m;
},{});
const packSM = (o) => Object.keys(o)
.reduce(
(m,k)=> (false===o[k]
? m
: [...m,( ('dead'===k || true === o[k]) ? k : `${k}@${Math.max(Math.min(parseInt(o[k]),9),0)}` )]
)
,[])
.join(',');
You can use them like this: let s = unapckSM(token.get('statusmarkers'));
s.blue = true;
s.green = 3;
s['some-status-marker']=2;
token.set('statusmarkers',packSM(s));
That only supports having one copy of each status marker, which is the way the UI handles things. For a more complicated way of doing it, which supports multiple status markers of each name, check out TokenMod's source, or my FlyMore script: <a href="https://app.roll20.net/forum/post/9880765/script-modification-request-flight-ability-to-set-status-marker-with-no-number/?pageforid=9888181#post-9888181" rel="nofollow">https://app.roll20.net/forum/post/9880765/script-modification-request-flight-ability-to-set-status-marker-with-no-number/?pageforid=9888181#post-9888181</a> If all you need to do is set and get a specific status, and you know the tag for it, you can use: let status = token.get(`status_sometag::12343`);
token.set(`status_sometag::12343`,3); If you have the token marker tag as a variable: const myStatus = 'sometag::12343';
let status = token.get(`status_${myStatus}`);
token.set(`status_${myStatus}`,3); By the way, if you're looking to support Custom Token Markers, look at libTokenMarkers , which lets you ignore the tag vs name problems you might run into: let frozen = libTokenMarkers.getStatus('frozen');
let frozen_value = token.get(`status_${frozen.getTag()}`);
token.set(`status_${frozen.getTag()}`, 3); libTokenMarkers also gives you some options for outputting the Token Marker images in chat: sendChat('',`<div>You are currently Frozen ${frozen.getHTML()}</div>`); Hope that helps!