Hi, is there an internal function to evaluate the max and min of a roll? I need it to handle criticals in my character sheet, I come up with an option that doesn't use eval, but I noticed that it doesn't work even if I use Function. The alternative is splitting m1 and m2 and looking for the operators and doing the math following the order of operation, but there should be a better way Note: for whomever is interested, yes the logical ('||') or return the first value between 2, if the first value is null, I wasn't aware of it, but it works. *update:* To be clear, when I said min and max I mean, the max and possible value a string 'xDy+z' (or more complex) can have. Eval and Function, allow me to do it, but they allowed in roll20. I was looking for a function already provided but I cannot find any. *update 2: thanks for GiGs for finding the bug. This is the version of the code that works* on("change:san_success change:san_failure",function(v){
getAttrs(['san_success','san_failure'], function(v){
let maxsan=v.san_failure;
let minsan=v.san_success;
let update={};
maxsan="("+maxsan+")";
minsan="("+minsan+")";
let m1 = minsan.toLowerCase().replace(/[\\+\\-\\*\\/]/gi,")$&(").replace(/[dD]/gi,'||');
let m2 = maxsan.toLowerCase().replace(/[\\+\\-\\*\\/]/gi,")$&(").replace(/[dD]/gi,'*');
update['maxsanloss']=Function('"use strict";return (' + m2 + ')')();
update['minsanloss']=Function('"use strict";return (' + m1 + ')')();
console.log(m1+"="+Function('"use strict";return (' + m1 + ')')());
console.log(m2+"="+Function('"use strict";return (' + m2 + ')')());
setAttributes(update,true);
});
});