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

Getting some strange results with rotation...

1367721484
Konrad J.
Pro
API Scripter
I just made this extremely simple script so I can see what values to expect.  Learned that top and left don't mean the top left corner of the token, but they mean the coordinates for the middle of the token. But with rotation I'm getting some strange results.  I rotate it to the right and got what I expected for awhile.  Then I started rotating it to the left and got -15 once.  Then I did it some more and I got 630 and other numbers.  I can't get it back to zero.  Am I doing something obviously wrong or could this be a bug with rotate? on("change:graphic", function(obj, prev) {          log(obj.get("top")+"/"+obj.get("left")+"/"+obj.get("rotation")); }); Here are some results from the log. "245/875/0" "245/875/-45" "245/875/225" "245/875/270" "245/875/315" "245/875/360" "245/875/315" "245/875/540" "245/875/360" "245/875/405" "245/875/450" "245/875/495" "245/875/540" Thanks for the help. I hope to quickly get better with javascript.  I've got an idea to help with rotation, but if it doesn't return proper results I'm stuck. :(
1367722632
Konrad J.
Pro
API Scripter
Not sure how I got the greater than 360deg.  Can't get it again after I set rotation to 0.  But I still get one thing definitely not right.  Rotating to the right gives results you would expect all the way to 27-deg.  Past that you get -1 to -89. "245,875 / 70 x 70 r:90" "245,875 / 70 x 70 r:135" "245,875 / 70 x 70 r:90" "245,875 / 70 x 70 r:180" "245,875 / 70 x 70 r:225" "245,875 / 70 x 70 r:270" "245,875 / 70 x 70 r:-45" "245,875 / 70 x 70 r:-83.12434926852556" "245,875 / 70 x 70 r:-3.2985713785899953"  
1367722773
Konrad J.
Pro
API Scripter
Rotating to the left causing all the numbers to start out negative?  And it goes past -360deg. 5,875 / 70 x 70 r:0" "245,875 / 70 x 70 r:-45" "245,875 / 70 x 70 r:-90" "245,875 / 70 x 70 r:-135" "245,875 / 70 x 70 r:-180" "245,875 / 70 x 70 r:-225" "245,875 / 70 x 70 r:-270" "245,875 / 70 x 70 r:-315" "245,875 / 70 x 70 r:-360" "245,875 / 70 x 70 r:-405"
Honestly the rotation value just comes straight from an underlying graphics library, I'm not really doing much with it. My guess is that you could just do for example -405%360 ("%" is the modulus operator in Javascript) to get the "always less than 360" value.
1367723759
Konrad J.
Pro
API Scripter
Ya, but from my tests there are a bunch of exceptions.  Nothing seems to make a lot of sense.  I even go some results up at 730deg.  Its going to be hard to make a script that does rotating whith so many possible outcomes to simply rotating the token. :(  Just my luck, the firsst thing I try is a bit wonky. :)  I'll keep on plugging away. Thanks!
730%360 = 10... Doing %360 should always give you the "correct" rotation, even if it goes up really, really high. Let me know if for some reason when it's reporting 730 it's not actually rotated 10 degrees.