No problem! I added a second argument and changed the argument parsing to take the numbers 1,2, or 3, optionally followed by an m or M to designate the max attribute. That should let you put them pretty much anywhere you like. The help: Usage: !set-side-number-in-bar CurrentSideBar NumSidesBar Where CurrentSideBar and CurrentSideBar are one of the numbers 1 , 2 , or 3 (or the result of an inline roll or attribute reference) optionally followed by n m or M to indicate the max part of the bar. The current side number will be written to the bar indicated in the first argument, the number of sides will be written to the bar in the second argument. For example, to write the current sides to bar 2 and the number of sides to bar2 max you would call !set-side-number-in-bar 2 2m So you'll probably want to call: !set-side-number-in-bar 2 3 Code: on('ready',()=>{
const processInlinerollsNative = (msg) => {
if(msg.hasOwnProperty('inlinerolls')){
return msg.inlinerolls
.reduce((m,v,k) => {
let ti=v.results.rolls.reduce((m2,v2) => {
if(v2.hasOwnProperty('table')){
m2.push(v2.results.reduce((m3,v3) => [...m3,v3.tableItem.name],[]).join(", "));
}
return m2;
},[]).join(', ');
return [...m,{k:`$[[${k}]]`, v:(ti.length && ti) || v.results.total || 0}];
},[])
.reduce((m,o) => m.replace(o.k,o.v), msg.content);
} else {
return msg.content;
}
};
const showHelp = (who,errorMsg) => {
sendChat('',`/w "${who}" <div><b>Usage:</b> <code>!set-side-number-in-bar CurrentSideBar NumSidesBar</code> Where <code>CurrentSideBar</code> and <code>CurrentSideBar</code> are one of the numbers <code>1</code>, <code>2</code>, or <code>3</code> (or the result of an inline roll or attribute reference) optionally followed by n <code>m</code> or <code>M</code> to indicate the max part of the bar. The current side number will be written to the bar indicated in the first argument, the number of sides will be written to the bar in the second argument. For example, to write the current sides to bar 2 and the number of sides to bar2 max you would call <code>!set-side-number-in-bar 2 2m</code></div>${errorMsg ? `<div><b>ERROR:</b> ${errorMsg}</div>`:''}`);
};
const barArgRegex = /^\s*(?<bar>[123])(?<isMax>[mM])?\s*$/;
on('chat:message',msg=>{
if('api'===msg.type && /^!set-side-number-in-bar(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){
let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname');
let args = processInlinerollsNative(msg).split(/\s+/).slice(1);
if(args.length < 2) {
showHelp(who);
return;
}
let currSide = `${args[0]}`.match(barArgRegex);
let numSides = `${args[1]}`.match(barArgRegex);
if(currSide && numSides){
(msg.selected || [])
.map(o=>getObj('graphic',o._id))
.filter(g=>undefined !== g)
.forEach(g=>g.set({
[`bar${currSide[1]}_${currSide[2] ? 'max' : 'value'}`]: g.get('currentSide'),
[`bar${numSides[1]}_${numSides[2] ? 'max' : 'value'}`]: decodeURIComponent(g.get('sides')).split(/\|/).length
}));
} else {
showHelp(who,`Invalid argument: ${!currSide ? `CurrentSideBar: <code>${args[0]}</code>` : ''} ${!numSides ? `NumSidesBar: <code>${args[1]}</code>` : ''}`);
return;
}
}
});
});