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

Change side of multi sided token based on a value from a character sheet

I'm currently trying to figure out following solution. I'm running Blades in the Dark game (but I don't believe system matters), and I'd like to have multisided token that would automatically change it's value based on the value of bar of this token. Let's assume I'll link token for character with stress value on the card. I'd like to have token image updated whenever stress value changes (have different graphic display current stress value instead of using vanilla bar. I'm assuming that if this is possible, this will require at least token mod, but honestly I don't know how to approach this idea.
1684247548

Edited 1684247751
The Aaron
Roll20 Production Team
API Scripter
Here's a script I wrote for that a few years ago.&nbsp; It's set up to look at bar 1, but you can change the number in BAR on line 3 to 1,2 or 3 to get the bar you want.&nbsp; BIAS is used to offset from the beginning of the list of images, which you can adjust if your numbers don't start at 1 (leave as is if your numbers are 1,2,3...).&nbsp; Note that this will only work for images in a User Library, so if you are using Marketplace images, you'll need to download them (select, hit Z, right click, save as, then drag them back in) and reupload them. /* global TokenMod */ on('ready',()=&gt;{ const BAR = 1; const BIAS = 1; ///////////////////////////////////////////// const BarProp = `bar${BAR}_value`; const getCleanImgsrc = (imgsrc) =&gt; { let parts = imgsrc.match(/(.*\/images\/.*)(thumb|med|original|max)([^?]*)(\?[^?]+)?$/); if(parts) { return parts[1]+'thumb'+parts[3]+(parts[4]?parts[4]:`?${Math.round(Math.random()*9999999)}`); } return; }; const handleGraphicChange = (obj,prev) =&gt; { if(parseInt(prev[BarProp]) !== parseInt(obj.get(BarProp))){ let sides = decodeURIComponent(obj.get('sides')).split(/\|/); let maxSides = sides.length||0; if(maxSides){ let currSide = parseInt(obj.get('currentSide'))||0; let newSide = Math.max(BIAS,Math.min(maxSides,obj.get(`bar${BAR}_value`)||BIAS)); if((currSide + BIAS) != newSide){ let imgsrc = getCleanImgsrc(sides[newSide-BIAS]); if(imgsrc) { obj.set({ currentSide: newSide, imgsrc }); } } } } }; on('change:graphic', handleGraphicChange); if('undefined' !== typeof TokenMod &amp;&amp; TokenMod.ObserveTokenChange){ TokenMod.ObserveTokenChange(handleGraphicChange); } }); Here's the original post:&nbsp;<a href="https://app.roll20.net/forum/post/10031967/how-to-synchronize-token-mod-and-bar-value/?pageforid=10032353" rel="nofollow">https://app.roll20.net/forum/post/10031967/how-to-synchronize-token-mod-and-bar-value/?pageforid=10032353</a>
That's Amazing! Thanks!
1684248192
The Aaron
Roll20 Production Team
API Scripter
No problem!
One question. I've managed to launch script, and in general it's working. However it seems to trigger for stress values starting from 1, and going up. However for this particular system, I'm interested in stress values starting from 0 to 9. And it seems like when I set value to 0, script is not doing anything. It's probably change of 1 parameter in the script, but sadly I'm not familiar with this programming language.
1684253921
The Aaron
Roll20 Production Team
API Scripter
Set BIAS to 0, and that should resolve it.&nbsp; Most humans thing of numbers starting at 1,2,3,4... but computers tend to like 0,1,2,3... so BIAS corrects from humans to computers by subtracting an offset (defaulting to 1).&nbsp; If you change it to 0, it should just line up with what you're doing.