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

API Script to Change Attribute with Macro

1519060117

Edited 1519060237
I have a Macro that changes a bubble value when run it using TokenMod; there's a dropdown to select whether it damages or heals, then a pop-up to enter a value. This worked great for me until I realized that, for characters, it didn't carry across pages because Macros don't change attributes. I'm trying to write an API script to give me that functionality. I currently have the following, based on code from the wiki and from  this post; //HP Attribute Modification //type "!modHP" to decrease HP on("chat:message", function(msg) {      if(msg.type == "api" && msg.content.indexOf("!modHP ") !== -1) {           var numdice = msg.content.replace("!modHP ", "");           var attribObj = findObjs({ type: 'attribute', characterid: character.id, name: "Hit Points" })[0];           if (attribObj) {                var hp = attribObj.get('current') -1;                attribObj.set('current', hp);           }      } }); Currently, if I'm doing this correctly, this would reduce the selected character's Hit Points attribute by 1 every time it ran. What I would like for this to do is to be able to reference a few variables from a macro to determine if it increases or reduces the HP attribute, and if so by how much; if I can do that, I could work this into the macro and continue using it for both character and non-character tokens. Is there a way to reference macro variables in API scripts, and if so how can I do it? For reference, this is the macro I'd be working this into; !token-mod --set bar2_value|[[@{selected|bar2}?{Action|Damage, - |Heal, + |, - }?{HP±|0}]]
1519061305
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You can use chatsetattr for this.
That’s certainly easier than coding it myself. Thanks!
1519075226
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
With both chatsetattr and token-mod, you can do sooooo much.