Only the value of the attribute is passed to the script, not the actual name. Here is another version that accepts an optional argument for attribute name that will show up as a tooltip when you mouse over the target number. on('ready',function()
{
on('chat:message',function(msg){
if(msg.type=='api' && msg.content.indexOf('!2d10')==0) {
try {
const macroName = '2d10';
let result;
let displayRolls
who = getObj('player',msg.playerid).get('_displayname');
let args = msg.content.split(/\s+/);
args.shift();
let r = [randomInteger(10), randomInteger(10)].sort((a,b)=>a-b);
if (args.length > 1) {
displayRolls = '[[' + r[0] + '(1d10)]] & [[' + r[1] + '(1d10)]] vs. target [[' + args[0] + ' (' + args[1] + ')]]';
} else {
displayRolls = '[[' + r[0] + '(1d10)]] & [[' + r[1] + '(1d10)]] vs. target [[' + args[0] + ']]';
}
if (r[0] <= parseInt(args[0])) {
//lowest roll less than or equal to target, output sum
result = '[[' + (r[0] + r[1]) + ' (Using sum of dice)]]';
} else {
//lowest roll greater than target, output highest die
result = '[[' + r[1] + ' (Using highest die)]]';
}
let output = `&{template:default} {{name=${macroName}}} {{Rolls=${displayRolls}}} {{Result=${result}}}`;
sendChat('', output);
}
catch(err) {
sendChat('',`/w "${who}" `+ 'Error: ' + err.message);
}
}
});
}); args[1] is the array element that holds the name of the attribute, if you want it somewhere else in the output. You can now call the script in one of the following ways: !2d10 @{charName|attribute} !2d10 @{charName|attribute} attributeName !2d10 anyNumber anyText_no_spaces