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 .
Advertisement Create a free account

Add Tokenmarker via script

Hello, Another month, another problem... I'm trying to automatically add an icon when a player cast a spell (I created a json inside the gm handout properties of the matching spell, so I'm simply adding an icon tag no problem on this side). I have try to add some code like the&nbsp; <a href="" rel="nofollow"></a> &nbsp;but it add the name inside the statusmarker property but it dosen't dispay anything. I guess it's due that I only add the name of the icon and not the id. Is it possible to get the id (i will uniquely name the marker in the tokenset). I know Aaron made the token mod but I can't call it from my script (and until now don't fully understand how it worked 'D).&nbsp; PS : Because of the string I add inside the statusmarker I try to clean it with an empty chain... very bad idea I though I have corrupted all the game. Fortunately it was only the map :)
The Aaron
Forum Champion
API Scripter
Here are some functions I've written for dealing with status markers / token markers: const unpackSM = (stats) =&gt; stats.split(/,/).reduce((m,v) =&gt; { 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) =&gt; Object.keys(o) .reduce( (m,k)=&gt; (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')); = true; = 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.&nbsp; 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:&nbsp; <a href="" rel="nofollow"></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('',`&lt;div&gt;You are currently Frozen ${frozen.getHTML()}&lt;/div&gt;`); Hope that helps!
Thank you very much for your pertinent and detail answer as always ! I will try to understand how it works even if I probably use the libTokenMarker which seems perfect for me !
The Aaron
Forum Champion
API Scripter
No problem!&nbsp; Definitely come back with more questions if you have them!
Thank you for your kind offer. For now everything working as intented. Just for information if you renamed your icon manually it seems it take some time to actualise the name in the memory even if you restart the game and the sandbox but today evrythings fine