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

[Request] Change an attribute based on rotation.

So I want to be able to change a single attribute of character based on the rotation of the token it represents. For example, if a I rotated the token (that is facing upwards) representing Character-A 45 degrees to the right, character A's 'rotation' attribute would change to 45. Then if I rotated the token again another 45 degrees, the attribute would change to 90. And if I rotated it all the way back left 90 degrees, the attribute would change back to 0. From what I can tell, the script I'm looking for above is somewhere in the 'Facing Indicator' script found here:&nbsp;<a href="https://app.roll20.net/forum/post/1903275/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/1903275/slug%7D</a> &nbsp;but is buried in the rest of the script haha. I don't know how to do it myself, but if someone could, or tell me how to (by literally telling me which lines to omit or add), strip that script down to do just the bit I described above, that would be helpful. Thanks. :) &nbsp;
1479045326

Edited 1479048411
The Aaron
Pro
API Scripter
That script does a whole lot more than what you're wanting. &nbsp;Here's a little snippet that should suffice: on('ready',function(){ &nbsp; &nbsp; "use strict"; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; var rotationAttributeName = 'rotation'; &nbsp; &nbsp; on('change:token',function(obj,prev){ &nbsp; &nbsp; &nbsp; &nbsp; if(obj.get('rotation') !== prev.rotation){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (findObjs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: 'attribute', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: rotationAttributeName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; characterid: obj.get('represents') &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })[0]||{set:_.noop}).set({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current: ((obj.get('rotation')%360)+360)%360 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; });&nbsp; }); When the rotation of a token is changed, if that token represents a character and that character has an attribute named 'rotation', it will set the attribute to the rotation (adjusting it to be between 0-360). You can change the attribute name on the 3rd non-blank line there. &nbsp;Let me know if you need an easy way to add the rotation attribute to a bunch of characters/tokens.
1479045741

Edited 1479045783
Lithl
Pro
Sheet Author
API Scripter
on('change:graphic', function(obj, prev) { var character, rotation; if (obj.get('rotation') === prev.rotation) return; if (obj.get('represents') === '') return; character = getObj('character', obj.get('represents')); rotation = findObjs({ type: 'attribute', characterid: character.id, name: 'rotation' })[0]; if (!rotation) { rotation = createObj('attribute', { characterid: character.id, name: 'rotation' }); } rotation.set('current', obj.get('rotation') % 360); }); I believe Roll20 does negative rotation values on tokens as well. If you want the rotation to always be in the range [0,360) instead of (-360,360), replace the last line with: rotation.set('current', obj.get('rotation') % 360 + (obj.get('rotation') &lt; 0 ? 360 : 0));
1479048491
The Aaron
Pro
API Scripter
That's a good point on the negative rotation. &nbsp;I didn't find a way to get it to be negative, but I added checking for it anyway.
Hey thanks guys! Works great. And I already managed to find the script--or it might be one of many scripts(?)--that adds attributes to selected tokens, so I'm good! Thanks again :D&nbsp;
1479067946
The Aaron
Pro
API Scripter
Great! Happy Rolling.