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

Is there an API to create a button that changes an attribute

Hi, I know nothing about API, my GM is pro so we can use them, all I want is a button, either on my OGL sheet or maybe my macro bar, to set my strength from 18 to say 10 and my dexterity from 12 to 2 (and revert back to original value if possible).
1523649209

Edited 1523649237
Dana Lexa
Sheet Author
I haven't used it myself but I believe that ChatSetAttr will let you write a macro that changes an attribute, and you can save that macro either as a character ability or as a macro to your macro bar.
1523649416
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
ChatSetAttr is the tool for changing (or creating or deleting) an attribute. That and Token-mod are the most essential scripts for me.
Hello guys,t hanks for taking the time to help me, I followed your advice we installed chatsetattr. I made a macro : !setattr [--options] --name bob bobson --strength|10 --dexterity|2 Now if I wanted to revert back to my usual stats, I know I could create a second macro !setattr [--options] --name bob bobson --strength|18 --dexterity|10 but that's a little clunky, and I could set a question inside the macro to reduce it to one button but that still too many clicks. Is there a way to toggle it on and off?
1523661514
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I was going to say that you would need to create a custom script, since macros are really lacking in the if-this-then logic type situations. But then it occurred to me that you could probably shuffle stats to a custom holding attribute. Let say you have value 10 in attribute A that you want to toggle with value 20. You could create arbitrary attributes A2 and A3.  This starts out as A=10, A2=20, A3 =whatever. You run chat-set which sets A3 to the value of A2 (A3 becomes 20) , A2 to the value of A1 (A2 becomes 10) and then A1 to the value of A3 (A1 becomes 20) . This winds up with A3=20, then A2=10 and then A1=20. Run the script again and A3 becomes 10, A2 becomes 20 and A1 becomes 10 again. Basically you shuffle the values around in a circle. I haven't tested this, and it's possible it may not work. I don't know if values in fields resolve sequentially, or all at once. It's worth a test.
1523661635
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
May I ask what sheet you are using? Some sheets have a modifiers, which might be easier to toggle than swapping values around. The Shaped Sheet for 5e does this quite handily, for instance, and the toggle is operable by chatsetattr.
I'm using OGL 5th edition. I'm sorry I must admit it's all too confusing to me.
1523674745
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
That's a nifty idea for handling that Keith.
1523691510
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
The logic might need a little tweaking, but I just ran a test and the action is sound enough. You can set multiple attributes by referencing the values from other attributes in one round robin command.
Could you guide through how I would go about doing that?
1523722583

Edited 1523726905
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
EDIT: Use Jakob's version below. It's much simpler and more elegant. Create two new attributes (alternateSTR and placeholder). Give the alternateSTR attribute the alternate value ("10" from your original example). The placeholder attribute can have any number. Zero would be a good test number so you can immediately see if something has gone wrong. You can do this with ChatSetAttr, but since this is likely for a single character, I would suggest not automating that. Your macro (a character Ability, not a collections macro, i.e. one written on Attributes and Abilities tab of the character sheet) would look something like the following. But like I said, the logic might need to be tweaked a bit to get the performance you are expecting. I haven't thoroughly tested this. Block 1 puts the alternate Str value  into a placeholder attribute. Block 2 puts the regular Str value into the alternate attribute. Block 3 puts the placeholder value into the Str attribute. You would need a separate macro for toggling your dexterity, requiring another attribute called alternatedex, but you could use the same placeholder attribute for either macro, since it is just a temporary holding area. Also, I have used "strength" and "dexterity" for the attributes. I don't use the OGL sheet, so those names might be different. Check your attribute names on the left hand side of the Attributes and Abilities tab of the character sheet. Finally two buts of advice: 1) test this on a throwaway character, just in case. and 2) if you are a player, your GM will need to toggle player access to ChatSetAttr (it's in the Config menu), if you are the one who is going to be running it. !setattr {{ --sel --replace --placeholder|@{selected|alternateSTR} }} !setattr {{ --sel --replace --alternateSTR|@{selected|strength} }} !setattr {{ --sel --replace --strength|@{selected|placeholder} }}
1523724449

Edited 1523724494
Jakob
Sheet Author
API Scripter
2) if you are a player, your GM will need to toggle player access to ChatSetAttr Nope, only if you're modifying a character you do not control, which wouldn't be the case here. Also, may I suggest this instead to make it work without a selected token and simplify it: !setattr {{ --name bob bobson --alternateSTR|@{bob bobson|strength} --strength|@{bob bobson|alternateSTR} --alternateDEX|@{bob bobson|dexterity} --dexterity|@{bob bobson|alternateDEX} }} This will just switch strength and alternateSTR for this character, and likewise for dexterity — there should not be any need for the placeholder attribute, since all the attribute values are evaluated when you send the macro.
1523726534
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Thanks Jakob. Like I said in my first post, I wasn't sure when values got were resolved, so I was playing it safe. That's much, much simpler.
1523726696
Jakob
Sheet Author
API Scripter
keithcurtis said: Thanks Jakob. Like I said in my first post, I wasn't sure when values got were resolved, so I was playing it safe. That's much, much simpler. Generally, @{xxx} attribute references, abilities, macros, queries, etc ... are resolved before the message is sent to chat. The API only ever sees the result after everything has been resolved (which is really annoying sometimes!).
1523726989

Edited 1523727787
Thank you Keith and Jacob for your help, it's exactly what I wanted, and it works seamlessly. I'm very grateful to the both of you. EDIT: I can't seem to be able to mark this topic as (SOLVED), my apologies.
1523737539
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Don't worry about it. That functionality doesn't really exist here. Cheers!