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

[BUG] sizing inaccuracies

November 19 (11 years ago)
I find that I need these four pieces of code. If I adjust a token to a size other than 1x1 unit, the width can become 140.00000000000001, or the left might be 804.999999999999 or the like.

on("change:token:left", function(obj, prev) {    
// Clean up fractional pixels
var oldValue = obj.get("left");
var newValue = Math.round(oldValue);
obj.set("left", newValue);
log("change:left "+oldValue+", "+newValue+", "+obj.get("left"));
});
on("change:token:top", function(obj, prev) {
// Clean up fractional pixels
var oldValue = obj.get("top");
var newValue = Math.round(oldValue);
obj.set("top", newValue);
log("change:top "+oldValue+", "+newValue+", "+obj.get("top"));
});
on("change:token:width", function(obj, prev) {
// Clean up fractional pixels
var oldValue = obj.get("width");
var newValue = Math.round(oldValue);
obj.set("width", newValue);
log("change:width "+oldValue+", "+newValue+", "+obj.get("width"));
});
on("change:token:height", function(obj, prev) {
// Clean up fractional pixels
var oldValue = obj.get("height");
var newValue = Math.round(oldValue);
obj.set("height", newValue);
log("change:height "+oldValue+", "+newValue+", "+obj.get("height"));
});



November 21 (11 years ago)
Riley D.
Roll20 Team
This has to do with the way that numbers are represented internally in Javascript. Is there a reason you're rounding them all off all the time? Internally having those decimals is fine by Roll20...
November 21 (11 years ago)
I makes distance calculations and other output look bad. 8)

And, it makes my situational OCD kick in.