Here's a script I wrote for that a few years ago. 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. 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...). 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',()=>{
const BAR = 1;
const BIAS = 1;
/////////////////////////////////////////////
const BarProp = `bar${BAR}_value`;
const getCleanImgsrc = (imgsrc) => {
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) => {
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 && TokenMod.ObserveTokenChange){
TokenMod.ObserveTokenChange(handleGraphicChange);
}
});
Here's the original post: <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>