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

[Request] - API that sets Bar3_value to the value of an attribute (just the value, doesn't set dropdown)

[Request] - API that sets Bar3_value to the value of an attribute (just the value, doesn't set dropdown). I need to get this done for every (multiple hundreds) of character sheets in my campaigns. Any assistance would be appreciated. Just need to do: !SetBar --bar3_value --AC Thanks!
1409082875
The Aaron
Roll20 Production Team
API Scripter
So, basically, you want to iterate across all tokens in the campaign, and se their bar3's value to the value of the AC attribute of the character they represent?
yes, oddly enough I think it should be very simple. I kind of ran into an issue is why I have to do this. I can't set a bar to be an AC value for creatures since if they remove their shield etc, I can't use the !mark with the target AC grab and still be able to use the bar to change it. So instead I have to briefly set the token bar to be the value of the AC, then set it back to none. The overall problem being that I just switched AC from bar2 to bar3 like an idiot to make bar2 for temp hp, sigh. I'm so short sighted! :(
It also looks like I am doing something wrong with trying to access the bar3 value. Target's AC @{target|Target 1|bar3_value}
I'm such a noob :) it should be Target's AC @{target|Target 1|bar3}
1409153738
The Aaron
Roll20 Production Team
API Scripter
I'm not clear on your use case. Are you planning to do this multiple times, or is this a one time fix?
One time fix per campaign.
1409156181

Edited 1409203945
The Aaron
Roll20 Production Team
API Scripter
Yeah, pretty straight forward: =D on('ready',function() { var ACByCharID = _.chain(findObjs({ type:'attribute', name:'AC' }, {caseInsensitive: true})) .reduce(function(memo,a){ memo[a.get('characterid')]=a.get('current'); return memo; },{}) .value() ; _.chain(findObjs({ type:'graphic', subtype: 'token' })) .filter(function(t){ return '' !== t.get('represents'); }) .filter(function(t){ return ACByCharID[t.get('represents')]; }) .each(function(t){ t.set({ bar3_value: ACByCharID[t.get('represents')], bar3_max: '' }); }) ; })
I don't quite get the On "Ready", I've seen it before in your scripts. I'm guessing I can just throw in an !apiname call for it.
1409163121
The Aaron
Roll20 Production Team
API Scripter
No, just throw that in it's own page and restart the sandbox and it will do the work. on('ready',...) just waits for everything to be loaded before acting. After you've restarted the sandbox once, everything will be updated and you can remove the script.
Wow, that is slick, no work on my end. Enable it, disable it, and bam :) Aaron to the rescue yet again.
1409164516
The Aaron
Roll20 Production Team
API Scripter
;)
hmm, it seems a bit buggy. I need a slight enhancement, I need it to set the max of bar 3 to nothing, and I need it to run all the way through. On ready doesn't seem to just fire on its own and go through all of the sheets. I'll probably have to switch it to the !aipname style as those seem to work.
1409204682
The Aaron
Roll20 Production Team
API Scripter
Updated to set max. I'm not clear on what other issue you're experiencing. I can add logging to verify that it is making adjustments if you like.
It just runs on tokens on map, or all sheets in my list? It wasn't doing either. Unless ready only runs at intervals.
1409236356
The Aaron
Roll20 Production Team
API Scripter
It only runs on tokens which are on a page. There is no way to access tokens that are stored as part of a character. I get the feeling that's where the confusion lies. You would still need to update characters to have the token with the right settings.
That's unfortunate that you can't access them. Even when I dropped ones on a page, it seemed to randomly update them over time. If that is the only solution, it might be better to have a !APINAME call to just manually run whenever I put tokens on a page and combat is about to begin. The longterm solution remains what I am in process of doing which is updating each creature to the beastiary/monster manual as it gets released (using basic and the modules for now). It seems like something I'll need access to just run whenever, and isn't going to be a one time thing due to not being able to access tokens tied to characters. This is a solution that I am just going to have to make work as I have to spend my time elsewhere updating for 5e, and not wasting time on the 5e (Next) playtest. Thank you once again Aaron.
1409250613
The Aaron
Roll20 Production Team
API Scripter
No worries. =D
Aaron, I tried to update my default marker script to include this as a solution, this isn't working (bolded is attempting to do what yours attempts): // Configure which attribute should be linked to which marker var CONFIG = [ {attribute: "Melee", marker: "red"}, {attribute: "Reaction", marker: "green"}, {attribute: "Shield", marker: "blue"}, {attribute: "Range", marker: "brown"}, {attribute: "Readied", marker: "yellow"}, {attribute: "Dropped", marker: "pink"}, {attribute: "Focus", marker: "purple"}, {attribute: "Critical", marker: "flying-flag"}, {attribute: "Fumble", marker: "black-flag"}, {attribute: "Torch", marker: "three-leaves"}, {attribute: "MageArmor", marker: "overdrive"}, {attribute: "TerrainPenalty", marker: "snail"}, {attribute: "ToolorReach", marker: "spanner"}, {attribute: "AlcoholDrinks", marker: "drink-me"}, {attribute: "DrunkenState", marker: "edge-crack"}, {attribute: "AsleepExhaust", marker: "sleepy"}, {attribute: "PassStealth", marker: "ninja-mask"}, {attribute: "PassOdor", marker: "half-haze"}, {attribute: "PassPerception", marker: "bleeding-eye"} ]; // Translate an attribute string to a marker value including some error checking // Returns null if the attribute can't be shown in a marker function attributeToMarker(attributeValue) { var markerValue = 0; attributeValue = attributeValue.trim(); if (attributeValue === "") return false; markerValue = parseInt(attributeValue); if (markerValue === 0) return false; else if (markerValue === 1) return true; else if (!markerValue || markerValue < 0) return null; else return markerValue; } // This is needed to so that tokens that are dragged on the table top from the journal // get markers on('ready', function() { on('add:token', function(obj){ var charId = obj.get("represents"); if (charId) { var ACByCharID = findObjs(({ _type: "attribute", name: 'AC', _characterid: charId }, {caseInsensitive: true})); if (ACByCharID) { obj.set('bar3_value', ACByCharID); } CONFIG.forEach(function(opts) { var attribute = findObjs({ _type: "attribute", name: opts.attribute, _characterid: charId })[0]; if (attribute) { var attributeValue = attribute.get("current"); var markerValue = attributeToMarker(attributeValue); if (markerValue === null) { log("Attribute value not valid!"); return; } obj.set("status_" + opts.marker, false); var wings = ''; while(markerValue > 0) { // get current digit, starting from ones var digit = markerValue / 10; digit -= Math.floor(digit); digit = Math.round(digit * 10); // shift markerValue markerValue = Math.floor(markerValue / 10); wings += opts.marker +'@'+digit+','; } if(wings.length > 0) wings = wings.substring(0, wings.length - 1); // trim trailing comma var markers = obj.get('statusmarkers'); if(markers != '') markers += ','; markers += wings; obj.set('statusmarkers', markers); } }); } }); }); any idea?
1409452089
The Aaron
Roll20 Production Team
API Scripter
obj.set('bar3_value', ACByCharID); ACByCharID is an object. You probably want: obj.set('bar3_value', ACByCharID.get('current'));
That, nor this is working : var ACByCharID = findObjs(({ _type: "attribute", name: 'AC', _characterid: charId }, {caseInsensitive: true}))[0]; if (ACByCharID) { var attributeValue = ACByCharID.get("current"); obj.set({bar3_value: attributeValue}); }
1409464727
The Aaron
Roll20 Production Team
API Scripter
I think I need a better definition of "not working". Is it crashing, or not updating?
Not updating.
1409490623
The Aaron
Roll20 Production Team
API Scripter
If this were my script, is be adding some log statements at this point. It's hard to see all that is going on without it being in code format. I'd log obj.get('name'), ACbyByCharID, obj.get('bar3_value') before and after and verify you are seeing what you expect to see.
Brute forcing it as simple as possible is working: var ACByCharID = getAttrByName(charId, "AC"); obj.set('bar3_value', ACByCharID);
Wow, even that doesn't work on every token, when there is clearly an attribute named "AC", sigh :/
Figured that one out, it wasn't tied to a character, every issue has been resolved, thanks Aaron.
1409504701
The Aaron
Roll20 Production Team
API Scripter
No problem!