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] script that resets bar value

1416439851
Tom
Pro
Sheet Author
So I've been sitting on a mentor subscription long enough to build a character sheet that I feel I should be doing more with it for my money. So time to look into API scripts. I have no experience with java scripting, so I'm hoping I can find existing scripts that can be easily repurposed. one that would be very useful for my group would be a script that resets the value of a bar to 0 on the character's initiative turn. Is there anything like that available?
1416440700
The Aaron
Roll20 Production Team
API Scripter
Not directly, but it would be pretty easy to write. I can help you with that either later tonight or tomorrow. So we're clear, this is what you are asking for: On a change in initiative order, the token that is now at the top of the turn order has one of its bars set to the value 0.
1416440868

Edited 1416440940
Tom
Pro
Sheet Author
Thanks Aaron. That's it exactly. Sorry it isn't sexier than that. Somewhere I have an API Wishlist scribbled down.
1416442346
The Aaron
Roll20 Production Team
API Scripter
No worries, just means it's easier for me to knock it out real quick. :) I love API wish lists. I've got about 10 design documents in Google docs I'd love to get to! :)
1416445129
The Aaron
Roll20 Production Team
API Scripter
Here ya go! on('ready',function(){ on('change:campaign:turnorder',function(c,oc){ var to = c.get('turnorder'), cTo = JSON.parse( to ? to : '[]' ), pTo = JSON.parse( oc.turnorder ? oc.turnorder : '[]'), barNum = '1', // Change this to whatever bar number you want to zero. t; if( (cTo.length && !pTo) || (cTo.length && pTo.length && cTo[0].id !== pTo[0].id) ) { t = getObj('graphic',cTo[0].id); if(t) { t.set('bar'+barNum+'_value', 0); } } }); });
1416514775
Tom
Pro
Sheet Author
And skipping over from the other thread... What would I have to change in the script to have it reset an attribute to zero each round under the same circumstances? (initiative order comes up). Weighing my options here.
1416514926
Tom
Pro
Sheet Author
And one more very stupid question that is probably in the wiki but I'm too lazy to look. If I ever drop my membership from Mentor level, the API just stops working, right? It's not going to blow up my entire campaign and require a whole new round of debugging?
1416516085
The Aaron
Roll20 Production Team
API Scripter
Setting an attribute to 0 should be like this (didn't test it though, but should be right...): on('ready',function(){ on('change:campaign:turnorder',function(c,oc){ var to = c.get('turnorder'), cTo = JSON.parse( to ? to : '[]' ), pTo = JSON.parse( oc.turnorder ? oc.turnorder : '[]'), barNum = '1', // Change this to whatever bar number you want to zero. attrName = 'SomeAttribute', // Change to whatever attribute you want to set t, a ; if( (cTo.length && !pTo) || (cTo.length && pTo.length && cTo[0].id !== pTo[0].id) ) { t = getObj('graphic',cTo[0].id); if(t) { t.set('bar'+barNum+'_value', 0); a=findObjs({type: 'attribute', characterid: t.get('represents'), name: attrName})[0]; if(a) { a.set({current: 0}); } } } }); }); Without your Mentor subscription, the API sand box never starts up for you games. As far as I understand it, you could go out of mentorship and your API stops doing anything (like it never existed). You can then subscribe at Mentor level again and everything is back the way it was.
1417813120
Tom
Pro
Sheet Author
Aaron, Thanks for the work on this. Just so I know what I'm doing, I'm replacing "SomeAttribute" and "attrName" with the proper name of the attribute (actionmod). Do I need to make that change anywhere else?
1417813505
Tom
Pro
Sheet Author
Hmmm... Got this error message: ReferenceError: actionmod is not defined at evalmachine. :16:80 at eval (
1417814451
The Aaron
Roll20 Production Team
API Scripter
attrName is a variable, you should only change 'SomeAttribute' to 'actionmod'.
1417815638
Tom
Pro
Sheet Author
AH! That would explain things.