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

Switching Bar 1 and Bar 3 (Make red be HP, green AC and blue be nothing)

Hey, so I need to make Bar 3 be the HP and Bar 1 be the AC (5th edition OGL sheet). I have the Tomb of Annihilation module so all the Monsters have green health. I know I can switch colors but I'd much rather just shift around the values of the bubbles. The values should end up unlinked to the values too.  Right now I'm opening a character sheet, put down the token, edit the token, edit the character sheet, delete old token and put in the newly edited token. there has to be a better way than to do this by hand.  I'm a total noob with API, basically I just look for APIs that tell me exactly how I can use them, otherwise I just don't use them cuz I can't. So if there is an API that does this, I'd very much appreciate being pointed in the right direction. I tried searching the forum but its tough to find things here. I want this: to change to this:  were the 10 in the second one is passive_perception but thats not important really. I'd love the script to to that for all character sheets currently in the campaign. Any way to do this except by hand? Thaaanks
1532380131
The Aaron
Pro
API Scripter
It would be easiest to fix it if you haven't changed anything yet.  Then a script could be created to just go through and swap the values of the bars and the links.   If you've already changed some, that would break things. If you've already updated a bunch and starting from a fresh copy of the module is not an option, it can still be done, it's just slightly more complicated.
i can easily undo it. because i did 4 and then thought that it would take me hours to do this, so I asked here. 
1532384234
The Aaron
Pro
API Scripter
This should fix them all: on('ready',()=>{ sendChat('Fixing Tokens',`/w gm Fixed ${findObjs({type:'graphic'}).map(t=>{ t.set({ bar1_link: t.get('bar3_link'), bar3_link: t.get('bar1_link'), bar1_value: t.get('bar3_value'), bar3_value: t.get('bar1_value'), bar1_max: t.get('bar3_max'), bar3_max: t.get('bar1_max') }) }).length} tokens`); });
Thank you very much this saves me a lot of time!  Just to confirm how this works. I have all the tokens on a page, activate the script by pasting your code into an API and saving it and then I'll go through all the character sheets and delete the old token and set the new token? This can not be automated right?
1532440057
The Aaron
Pro
API Scripter
Ah, great question, let me rewrite this: on('ready',()=>{ const fixToken = (t) => { t.set({ bar1_link: t.get('bar3_link'), bar3_link: t.get('bar1_link'), bar1_value: t.get('bar3_value'), bar3_value: t.get('bar1_value'), bar1_max: t.get('bar3_max'), bar3_max: t.get('bar1_max') }); let c = getObj('character',t.get('represents')); if(c){ setDefaultTokenForCharacter(c,t); } }; const workQueue = findObjs({type:'graphic'}); const drainQueue = ()=>{ let t = workQueue.shift(); if(t){ fixToken(t); setTimeout(drainQueue,0); } else { sendChat('Fixing Tokens',`/w gm Finished Fixing Tokens`); } }; sendChat('Fixing Tokens',`/w gm Fixing ${workQueue.length} Tokens`); drainQueue(); }); There, now it will also update the default character, if they represent a character.  Just put that in an API script and save it, and it should fix all the things.  Try it in a duplicate campaign first though, just in case.
This is simply amazing. Thank you so much! it worked like a charm! If you're ever in Berlin, lemme know and come get a beer or 5. :) THANKS!
1532443307
The Aaron
Pro
API Scripter
=D No worries. =D
1532460708
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Also, as a note, if you were only wanting to swap the bar representing a given attribute due to the colors, you as the gm can change the colors of the bars in the settings side panel:
Denis said: ... I know I can switch colors but I'd much rather just shift around the values of the bubbles. ... I alluded to this but you are right it's a good addition incase someone else finds this through google and might wanna do the same but doesn't wanna do API. Thanks for that. For me personally this wasn't the best solution because the players already have their bars and we have quite a few players. And this way I get to use the monsters in another campaign too.