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

Using API to set linked bar value does not update all representative tokens

I have two tokens on different pages that represent the same character with the bars linked to character attributes (like hit points).  However when I use obj.set("bar3_value",5) it works correctly on the token I was referencing but does not seem to adjust the token on the other page.  If I changed bar3 manually everything seems to work fine it just seems like it doesn't work if changed through API.  Any help would be appreciated. thanks
1471827273
Lithl
Pro
Sheet Author
API Scripter
Have you tried changing the attribute bar3 is linked to instead of changing bar3?
I have not tried that yet but that would seem to invalidate the purpose of having the links right?
1471923814
Lithl
Pro
Sheet Author
API Scripter
Not entirely; assuming it works, updating the attribute would update all of the appropriate bars, so the link is still providing benefit. It may also be that there's a bug making the other token not update correctly, rather than intended behavior of bars/links.
Okay, thanks.  I'll consider giving that a try. However since it will be a lot of coding for me to redo I'll see if I get away with just copying the current tokens to the new page as needed instead of having them setup on the new page before hand. thanks again for taking the time to respond to my question.
1472043140
The Aaron
Pro
API Scripter
You can probably use this function to make the change painless: var setBarRep = function(t,b,v,max){     'use strict';      let brep=t.get(`bar${b}_link`),         battr=brep && getObj('attribute',brep);     max=(max||false);     if(brep && battr){         battr.set( (max ? 'max' : 'current'), v);     } else {         t.set(`bar${b}_${ max ? 'max' : 'value'}`, v);     } }; Instead of: token.set('bar1_value,5); You can do: setBarRep(token,1,5); If bar1 represents an attribute, it will get set, otherwise it will set the value on the token. If you want to set the max: setBarRep(token,1,5,true);
Thanks Aaron. I'll give this a try