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

API: Token attributes no longer populated

1436088366
Kryx
Pro
Sheet Author
API Scripter
Previously available token attributes seem to no longer be accessible - except "represents". on('add:graphic', function(obj) { shaped.rollTokenHp(obj); }); shaped.rollTokenHp = function(token) { var represent = token.get('represents'); log('token'); log(token); log('represents'); log(token.get('represents')); }; Is the simplified code. This what what I get back from logging: "token" {"_id":"-JtSVloW0Otqs8sRGB4i","_pageid":"-Jo5uD126osvTMT22wcm","left":2316,"top":1130,"width":70,"height":70,"rotation":0,"layer":"objects","isdrawing":false,"flipv":false,"fliph":false,"imgsrc":"<a href="https://s3.amazonaws.com/files.d20.io/marketplace/45150/mVF1Ja-NbubLsozQAPKxPw/max.png?1412260214&quot;,&quot;name&quot;:&quot;&quot;,&quot;gmnotes&quot;:&quot;&quot;,&quot;controlledby&quot;:&quot;&quot;,&quot;bar1_value&quot;:&quot;&quot;,&quot;bar1_max&quot;:&quot;&quot;,&quot;bar1_link&quot;:&quot;&quot;,&quot;bar2_value&quot;:&quot;&quot;,&quot;bar2_max&quot;:&quot;&quot;,&quot;bar2_link&quot;:&quot;&quot;,&quot;bar3_value&quot;:&quot;&quot;,&quot;bar3_max&quot;:&quot;&quot;,&quot;bar3_link&quot;:&quot;&quot;,&quot;represents&quot;:&quot;-JgktffSqc1TM8hfxu_Y&quot;,&quot;aura1_radius&quot;:&quot;&quot;,&quot;aura1_color&quot;:&quot;#FFFF99&quot;,&quot;aura1_square&quot;:false,&quot;aura2_radius&quot;:&quot;&quot;,&quot;aura2_color&quot;:&quot;#59E594&quot;,&quot;aura2_square&quot;:false,&quot;tint_color&quot;:&quot;transparent&quot;,&quot;statusmarkers&quot;:&quot;&quot;,&quot;showname&quot;:false,&quot;showplayers_name&quot;:false,&quot;showplayers_bar1&quot;:false,&quot;showplayers_bar2&quot;:false,&quot;showplayers_bar3&quot;:false,&quot;showplayers_aura1&quot;:false,&quot;showplayers_aura2&quot;:false,&quot;playersedit_name&quot;:true,&quot;playersedit_bar1&quot;:true,&quot;playersedit_bar2&quot;:true,&quot;playersedit_bar3&quot;:true,&quot;playersedit_aura1&quot;:true,&quot;playersedit_aura2&quot;:true,&quot;light_radius&quot;:&quot;&quot;,&quot;light_dimradius&quot;:&quot;&quot;,&quot;light_otherplayers&quot;:false,&quot;light_hassight&quot;:false,&quot;light_angle&quot;:&quot;&quot;,&quot;light_losangle&quot;:&quot;&quot;,&quot;light_multiplier&quot;:1,&quot;sides&quot;:&quot;&quot;,&quot;currentSide&quot;:0,&quot;lastmove&quot;:&quot;&quot;,&quot;_type&quot;:&quot;graphic&quot;,&quot;_subtype&quot;:&quot;token&quot;,&quot;_cardid" rel="nofollow">https://s3.amazonaws.com/files.d20.io/marketplace/45150/mVF1Ja-NbubLsozQAPKxPw/max.png?1412260214","name":"","gmnotes":"","controlledby":"","bar1_value":"","bar1_max":"","bar1_link":"","bar2_value":"","bar2_max":"","bar2_link":"","bar3_value":"","bar3_max":"","bar3_link":"","represents":"-JgktffSqc1TM8hfxu_Y","aura1_radius":"","aura1_color":"#FFFF99","aura1_square":false,"aura2_radius":"","aura2_color":"#59E594","aura2_square":false,"tint_color":"transparent","statusmarkers":"","showname":false,"showplayers_name":false,"showplayers_bar1":false,"showplayers_bar2":false,"showplayers_bar3":false,"showplayers_aura1":false,"showplayers_aura2":false,"playersedit_name":true,"playersedit_bar1":true,"playersedit_bar2":true,"playersedit_bar3":true,"playersedit_aura1":true,"playersedit_aura2":true,"light_radius":"","light_dimradius":"","light_otherplayers":false,"light_hassight":false,"light_angle":"","light_losangle":"","light_multiplier":1,"sides":"","currentSide":0,"lastmove":"","_type":"graphic","_subtype":"token","_cardid</a>":""} "represents" "-JgktffSqc1TM8hfxu_Y" Name is blank, bar values are blank, bar_links are blank. Here is the actual token: Any reason why this may be happening?
1436106524
The Aaron
Roll20 Production Team
API Scripter
I've found that the add:graphic sometimes occurs before the token is wholly setup. My TokenNameNumber script records the ID on add:graphic, the checks for the same ID during change:graphic event and applies changed to the token at that time, then removes it from the list of IDs to watch for. You might give that a try?
1436123965
Kryx
Pro
Sheet Author
API Scripter
Seems like a bug that should be fixed - a timing issue. I could work around it as you said, but that's taxing on all devs to add these other listeners and then remove them.
1436213602
Stephen Koontz
Forum Champion
Marketplace Creator
Sheet Author
API Scripter
Compendium Curator
Mark are you getting this from the duplicate functionality in app or how exactly are you running into this issue?
1436214204
Kryx
Pro
Sheet Author
API Scripter
Duplicate functionality? I'm getting it from my API script which watches for tokens to be dropped and then checks if they are NPCs and if they have a linked bar to their HP to see if it should roll random HP for the creature. It fails in being able to determine if the HP bar is linked to an attribute. Accessing the journal seems fine, but it seems Aaron is correct that the token isn't fully setup. Adding a timeout of 100ms seems to fix it consistently. A timeout of 0ms seems to never fix it. A timeout of 10ms seems to fix it about half the time.
So what's happening here is when you drop a Character onto the tabletop, it first creates the token, then loads the token with all of the default attributes for the default token assigned to the character. The delay of 100ms works fine for you because your latency to the server is less than 100ms, however for example if you had a high latency player they would need a longer delay. I'll work on better documenting this on the Wiki. However I'm not sure if this behavior is going to change since the client can't (due to the way it functions) assign all properties on the new graphic right away. The best thing might be to have some sort of ability to do on("graphic:complete") or some other type of event that signals "this graphic is totally done being set up".
1436294377
Kryx
Pro
Sheet Author
API Scripter
Ya, I understand that the timeout would not be a fix that worked for everyone - I assumed it was the server response time. I was merely trying to test it to give you info in case it helped at all. You could use promises to wait for the async call to complete before returning the "add:graphic" event, but as you say that would require some changes.