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

Help! Graphic properties not updating for new/created graphics objects

1586242238

Edited 1586293139
I'm trying to make a token dropper that uses only the graphics item to keep track of very specific stats for high quantity trash monsters.&nbsp; I am using the add:graphic &nbsp;event to inspect and manipulate the information of the new graphic.&nbsp; I do several tests, including looking for a "TokenDropper" attribute of the character represented by the token and seeing if it's 'on'.&nbsp; That leads up to checkpoint 6 and then checkpoint 7 shows up in chat without fail, every time, but the properties of the graphic get updated only half of the time.&nbsp; You would think that it would work, or that it won't, but why only half of the time, off-and-on-and-off-and-on-again???&nbsp; By-and-large I'm not seeing errors in the API console.&nbsp; I put a link to two versions of the full code below.&nbsp; Can anyone help me out??? sendChat('Checkpoint 6', 'Preparation for Token update complete.'); obj.set({ represents:null, //Yes I do want to break the tie to the character sheet - these are trash tokens that I need only 1 character sheet for. name:strTokenName, bar1_value:numHPRoll, bar2_value:getAttrByName(objDroppedChar.id, "npc_speed"), bar3_value:getAttrByName(objDroppedChar.id, "npc_ac"), bar1_max:numHPRoll }); sendChat('Checkpoint 7', 'Dropped Token Updated.'); <a href="https://gist.github.com/ChrisScripts/edc0ee0023518c9d6b96e83c88c10bf4" rel="nofollow">https://gist.github.com/ChrisScripts/edc0ee0023518c9d6b96e83c88c10bf4</a>
1586265584
The Aaron
Roll20 Production Team
API Scripter
Because of the way some changes to Roll20 were implemented several years ago, the graphics do not get added fully formed. If you log events, you'll see that dragging graphics in results in an "add:graphic" with little more than an ID, followed by 1-7 "change:graphic" events.&nbsp; You can look at TokenNameNumber for an example of dealing with this annoyance, but the basic method is to store the ID when the "add:graphic" event occurs, then set a timer to check for a fully fleshed out graphic, with further deferring until it's ready.&nbsp;
1586271930

Edited 1586272408
Thank You!!! I never would have solved this issue.&nbsp; You may very well have saved my sanity and Roll20 a loss of a user account.&nbsp; LOL.&nbsp;&nbsp; Sorry for sounding like a newb, but I loaded the TokenNameNumber script to my game, but I can't see the source code.&nbsp; Is there an option that I have to configure in Roll20 somewhere or do you have a link to the code that I can look at?
1586277838
Dumbhuman
Pro
Marketplace Creator
Chris C. said: Thank You!!! I never would have solved this issue.&nbsp; You may very well have saved my sanity and Roll20 a loss of a user account.&nbsp; LOL.&nbsp;&nbsp; Sorry for sounding like a newb, but I loaded the TokenNameNumber script to my game, but I can't see the source code.&nbsp; Is there an option that I have to configure in Roll20 somewhere or do you have a link to the code that I can look at? When you select something from the Roll20 API Script Library dropdown, you're presented with the option to Install or Import.&nbsp; Install won't allow you to see the source code, because it will automatically update that source code should a newer version be made available.&nbsp; However if you choose Import instead that will add the source code as though you had simply pasted it in as a new script. There's also this GitHub repository of Roll20 Scripts that you might find useful.&nbsp; It includes TokenNameNumber of course.
1586278595
The Aaron
Roll20 Production Team
API Scripter
Woot, thanks KC.! This multiple events thing drove me crazy for several weeks a few years ago (So much so I wrote an ~800 line event debugging script to track down the behavior!).&nbsp; I'm still a bit sore about the changes as it breaks the interface contract between Roll20 and the API.&nbsp; If you do end up logging out all those events, you'll see that the "add:graphic" has almost nothing in it, and the subsequent "change:graphic" events are mostly identical.&nbsp; Very annoying, but it only happens on token creation, which tends to be something you don't trigger on so often (though it can bite you on scripts that trigger on change events).
Thanks for the tip KC!&nbsp; I see the code now.&nbsp; Aaron, Thanks for making and sharing the code.&nbsp; Looks like I'll be doing a deep-dive into this tonight. I'm all-ears if you got any advice that'll keep me from experiencing the same mental torture you went through a few years back.&nbsp; I hope I can get this working soon.&nbsp; I got a graveyard gauntlet coming up for my game this Friday.&nbsp; I see loads of zombies, skeles, crawling claws, ghasts and ghouls in the near future.