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

Trouble changing attributes in mod of The Aaron's Facing script

1534551289

Edited 1534551510
Attempting to modify the Facing script but this is my first time.&nbsp; I don't entirely understand the code because there are "pairs" which is something I haven't seen before. <a href="https://github.com/shdwjk/Roll20API/blob/master/Facing/Facing.js" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/Facing/Facing.js</a> I want to get the original dimensions of the graphic I use for the facing marker.&nbsp; I don't know how to find it and add it as an attribute of the "slave" object.&nbsp; I also want to add a hidden attribute but having difficulty adding that.&nbsp; My comments in the code are what I'm trying to do. Trying to create the hidden attribute and dimensions of image: &nbsp; &nbsp; createRinged = function(id) { &nbsp; &nbsp; &nbsp; &nbsp; // get root obj &nbsp; &nbsp; &nbsp; &nbsp; var master = getObj('graphic',id), &nbsp; &nbsp; &nbsp; &nbsp; slave = getRinged(id), &nbsp; &nbsp; &nbsp; &nbsp; layer; &nbsp; &nbsp; &nbsp; &nbsp; if(!slave &amp;&amp; master) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer=( 'gmlayer' === master.get('layer') ? 'gmlayer' : 'map'); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; slave = createObj('graphic',{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imgsrc: state.Facing.config.image, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer: layer, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageid: master.get('pageid'), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top: master.get('top'), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left: master.get('left'), height: 300, //should be original height of image width: 300, //should be original width of image //hidden: false, doesn't work when just adding at creation of this object &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rotation: master.get('rotation'), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &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: state.Facing.config.attributeName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; characterid: master.get('represents') &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })[0] || (master.get('represents') &amp;&amp; createObj('attribute',{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: state.Facing.config.attributeName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; characterid: master.get('represents') &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })) || { set: function(){} }).set({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current: slave.get('rotation') &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp;&nbsp;&nbsp;&nbsp;( createObj('attribute', { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: 'hidden', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;characterid: slave.id, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;current: false &nbsp;&nbsp;&nbsp;&nbsp;})); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if('gmlayer' === layer) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; toBack(slave); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; toFront(slave); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; state.Facing.ringed[master.id]=slave.id; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }, Trying to change size of image to 0 and back to previous value so I can hide it: &nbsp; &nbsp; hide = function(id) { &nbsp; &nbsp; &nbsp; &nbsp; var pair=getRingedPair(id); var height=pair.slave.get('height'); var width=pair.slave.get('width'); &nbsp; &nbsp; &nbsp; &nbsp; if(pair) { &nbsp;&nbsp;&nbsp;&nbsp;if(height === 0 &amp;&amp; width === 0) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pair.slave.set({ &nbsp;&nbsp;&nbsp;&nbsp;width: 300, //would like prev.width &nbsp;&nbsp;&nbsp;&nbsp;height: 300, //would like prev.height &nbsp;&nbsp;&nbsp;&nbsp;hidden: false &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}) &nbsp;&nbsp;&nbsp;&nbsp;} else { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pair.slave.set({ &nbsp;&nbsp;&nbsp;&nbsp;height: 0, &nbsp;&nbsp;&nbsp;&nbsp;width: 0, &nbsp;&nbsp;&nbsp;&nbsp;hidden: true &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; }, Trying to use the hidden attribute later on: handleTokenChange = function(obj,prev) { var pair = getRingedPair(obj.id), layer, rot, angle, hid; if(pair) { if(pair.master.id === obj.id) { layer=( 'gmlayer' === pair.master.get('layer') ? 'gmlayer' : 'map'); rot=pair.master.get('rotation'); angle = rot - prev.rotation; hid = pair.slave.get('hidden'); //hid = findObjs({ type: 'attribute', characterid: pair.slave.id, name: 'hidden' })[0]; //not able to get the hidden attribute either way for the If statement below if(rot !== prev.rotation ) { &nbsp;&nbsp;&nbsp;&nbsp;if(hid === false) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pair.master.set({ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rotation: prev.rotation, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); pair.slave.set({ &nbsp;&nbsp;&nbsp;&nbsp;rotation: rot }); &nbsp;&nbsp;&nbsp;&nbsp;} else { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pair.slave.set({ &nbsp;&nbsp;&nbsp;&nbsp;rotation: (pair.slave.get('rotation') + angle) }); &nbsp;&nbsp;&nbsp;&nbsp;} } &nbsp;&nbsp;&nbsp;&nbsp; pair.slave.set({ layer: layer, top: pair.master.get('top'), left: pair.master.get('left'), }); if('gmlayer' === layer) { toBack(pair.slave); } else { toFront(pair.slave); } } else { pair.slave.set({ width: prev.width, height: prev.height, top: prev.top, left: prev.left, layer: prev.layer, flipv: prev.flipv, fliph: prev.fliph }); } } },
1534553124

Edited 1534553477
The Aaron
Pro
API Scripter
The original size of an image is not available to the API.&nbsp; If you know what it is, you can just hard code it, or you could prompt for it in the configuration.&nbsp; Either way, you'd need to store it somewhere in a mostly manual manner. Attributes are tied to characters.&nbsp; If you look on line 78, you can see where it finds an attribute for the character represented by the token that has a facing applied to it. The concept of Pairs is just something I put together for this script.&nbsp; It's similar to the way Bump has a master and slave id for Bump'ed tokens.&nbsp; Line 74 is where it builds a pair object that is returned to the rest of the script.&nbsp; In the state, it stores the facing information in state.Facing.ringed, which is an object where the key (property name) is the id of the token and the value is the id of the Facing Graphic associated with it.
Thanks, that's helpful.&nbsp; I think I understand getting the attribute in line 78 (although I would have thought the characterid would be "masterid".&nbsp; The 'represents' and set:function &nbsp;are a little beyond me).&nbsp; But how do you create a&nbsp; new attribute?&nbsp; I tried the following in the createRinged function because it looked similar to line 117 but it didn't work.&nbsp; And adding it directly as another attribute below 117 didn't work either. ( createObj('attribute', { &nbsp;&nbsp;&nbsp;&nbsp; name: 'hidden', &nbsp; &nbsp; characterid: slave.id, &nbsp;&nbsp;&nbsp;&nbsp; current: false }));
1534563323
The Aaron
Pro
API Scripter
The master and slave ids are for Graphics (Token is a subtype of Graphic, as is Card). Graphics can be associated with Characters via the Represents property. Attributes are associated with Characters, not Graphics, so you must get the Character ID from a token. Represents is literally the Character ID, so you can get it.&nbsp; Having covered all that, I’m not sure Attributed are what you want here. Can you back up and spell out what you’re trying to accomplish? There may be an easier way to achieve it.&nbsp;
In the hide function above I toggle the size of the facing graphic to 0x0 and back, effectively hiding it.&nbsp; I wanted a true/false attribute that would tell me if it was hidden.&nbsp; I just now realized I could just check if the dimensions are 0x0 in the handleTokenChange function.&nbsp; I think I got it working now.&nbsp; I'll post the script when it's finished.&nbsp; The purpose is to have a LOS marker that I can turn off and on and will stay fixed relative to the token no matter how I rotate the token.&nbsp; It's for a miniatures game.
Sorry, one last question.&nbsp; I am having trouble getting "prev.height" and "prev.width".&nbsp; In line 228 and 229 of your code you seem to just set it but when I try it doesn't work.&nbsp; here is my code below.&nbsp; I've also tried obj.set("height") and prev["height"] from this post but I get an error that obj.get is not a function. hide = function(id, obj, prev) { &nbsp; &nbsp; &nbsp; &nbsp; var pair=getRingedPair(id); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var height=pair.slave.get('height'); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var width=pair.slave.get('width'); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var h=obj.get('height'); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var w=obj.get('width'); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var prevheight = prev.height; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var prevwidth = prev.width; &nbsp; &nbsp; &nbsp; &nbsp; if(pair) { if(height === 0 &amp;&amp; width === 0) { pair.slave.set({ width: prevwidth, height: prevheight }) } else { pair.slave.set({ height: 0, width: 0 }); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; },
1534702197

Edited 1534702244
The Aaron
Pro
API Scripter
What are you passing for the parameters?&nbsp; That would indicate that whatever obj is in the call is not a Roll20 Object (because it doesn't have a .get() and probably not a .set() either).&nbsp; Try logging it to the console with: log(obj);
huh, I'm getting the player name not the image.
1534703028
The Aaron
Pro
API Scripter
If you want to link me to your whole code, I can take a peek.&nbsp; Or you can PM me an invite and GM me.
Thanks, here is the gist <a href="https://gist.github.com/bigbucy/bd09a5c51dc8a65c64cbbafad2fcf6ad" rel="nofollow">https://gist.github.com/bigbucy/bd09a5c51dc8a65c64cbbafad2fcf6ad</a>
1534703948

Edited 1534704022
The Aaron
Pro
API Scripter
Ok. The issue is you're passing it the name of the player that is calling the command: hide(s._id, who ); That will be the display name of the player from msg.playerid. It might be easiest to just remove the LOS token instead of hiding it.&nbsp; In fact, that's what !los will do if you call it on a token that has the indicator.
whoops, I just copied that without editing it.&nbsp; I originally was going to just remove it but I couldn't figure out how to save the rotation of the LOS for when it was turned back on.
1534705202

Edited 1534705258
The Aaron
Pro
API Scripter
Ah.&nbsp; It already stores the rotation in an attribute named rotation .&nbsp; You could reorganize the createRinged() function so that it loads that attribute if it exists and uses its value to set the rotation of the created facing/LOS marker: createRinged = function(id) { // get root obj var master = getObj('graphic',id), slave = getRinged(id), layer; if(!slave &amp;&amp; master) { layer=( 'gmlayer' === master.get('layer') ? 'gmlayer' : 'map'); let attr = (findObjs({ type: 'attribute', name: state.Facing.config.attributeName, characterid: master.get('represents') })[0] || (master.get('represents') &amp;&amp; createObj('attribute',{ name: state.Facing.config.attributeName, characterid: master.get('represents'), current: master.get('rotation') })) || { set: ()=&gt;{},get:()=&gt;master.get('rotation') }); slave = createObj('graphic',{ imgsrc: state.Facing.config.image, layer: layer, pageid: master.get('pageid'), top: master.get('top'), left: master.get('left'), height: 300, width: 300, rotation: attr.get('rotation') }); if('gmlayer' === layer) { toBack(slave); } else { toFront(slave); } state.Facing.ringed[master.id]=slave.id; } },