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

Sheetworker Script for Min-Max Function

1512427913
Axel
Pro
Sheet Author
Hey folks! I'm looking for some help with scripting because I'm not proficient enough to work this properly. I know that this works fine: //Autocalc <input type="hidden" name="attr_max_xy" value="(((@{x} + @{y}) + abs(@{x} - @{y})) / 2)" disabled> I would like to use a script to accomplish the same thing, but I can't quite get it working. This is what I've got: //Sheetworker on("change:x change:y", function() { getAttrs(["x", "y"], function(values) { setAttrs({ calc_xy: (((parseInt(values.x) + parseInt(values.y) + Math.abs(values.x) - parseInt(values.y))) / 2) }) }); }); What am I doing wrong?
Try this //Sheetworker on("change:x change:y", function() {   getAttrs(["x", "y"], function(values) { var x = parseInt(values.x), y = parseInt(values.y);     setAttrs({       calc_xy: (x + y + (Math.abs(x - y) / 2));     })   }); });
1512438197

Edited 1512438259
Kyle G. said: Try this //Sheetworker on("change:x change:y", function() {   getAttrs(["x", "y"], function(values) { var x = parseInt(values.x), y = parseInt(values.y);     setAttrs({       calc_xy: (x + y + Math.abs(x - y)) / 2     });   }); }); If this is to get the max of (x, y) you need to fix the parens. But you can also do this: //Sheetworker on("change:x change:y", function() { getAttrs(["x", "y"], function(values) { var x = parseInt(values.x), y = parseInt(values.y); setAttrs({ calc_xy: Math.max(x, y) }); }); });