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 .
Advertisement Create a free account Compendium in Game, Join Today

ChatSetAttr Issues With Setting Values

1599785982
Toki
Pro
Hi all! I'm hoping someone can help me troubleshoot an issue I'm having with trying to set an attribute via ChatSetAttr. I have a variable, AP, defined as: <span class="text">AP</span> <span class="curr"><input type="number" name="attr_ap"></span> <span class="max">MAX: <span name="attr_ap_max" ></span> <input type="hidden" value="0" name="attr_ap_max" readonly> </span> I'm trying to use ChatSetAttr to send a message in chat and increment the value by 1 with the following: &{template:default} {{name=AP Test}} !setattr --name @{character_name} --ap|{{Recharge AP=[[@{ap}+1]]}}!!! {{desc=@{character_name} steadies themselves.}} I get a message stating the value should be be 1, but it remains 0: I'm suspecting the initial value isn't being read, but even when setting a value, it continues to set it to 0. Anyone have any idea what I'm doing wrong?
1599788962
Kraynic
Pro
Sheet Author
It looks like ap_max has a default value, but ap does not.  Does it work if you have value="0" in the ap line as well?
I know this is likely a dumb question, but if the value of attr_ap_max is 0, doesn't that act as an upper bound on attr_ap? If you use ` @{ap}-1`  in your call, does ap= -1, -2, -3, etc?
1599806606
GiGs
Pro
Sheet Author
API Scripter
It's quite possible to set an ap_max score below the actual ap score. The two stats are completely independent. The only thing ap_max is for is showing the health bars on tokens, and if the AP score is above AP_max, you'll just see a + on the end of the bar to show the bar is bigger (or will see the bar hang over the edge of the token in the old format). If you want ap_max to actually limit the ap score, you need to program a sheet worker to manage that.
1599839683
Toki
Pro
Thank you all for replying! So I tried setting value="0" on the ap line, but had no change in behavior. I have also tried with no value fields on either tag with no change. Curiously enough, when I do '-1', I'm seeing proper subtraction. The ap field updates to negative numbers (and I see a '-' on the token). Going back to '+1', there is proper addition until it hits 0, where it stays. I can force the ap field into a positive number, run the macro, and see proper addition in the result. But the field resets to 0 and never moves (and subsequent macro runs always shows a 1). The only sheet worker logic I have in place regarding AP is modifying the ap_max field when the character levels. When I'm loading the game and sheet, ap_max is 12. So, I'm stumped. :( The most that I can figure out is that -something- is not allowing the input field to change.
1599870055
Toki
Pro
Well, I wasn't able to figure out what the issue was, so I wound up playing with the API and writing a script that I can trigger via a Roll button (e.g., "!steady 2) to update the variable and send a message in chat. Sharing my code in case it happens to help someone else out! on("chat:message", function(msg) {   if(msg.type == "api" && msg.content.includes("!steady")) {     var playerChar = findObjs({ type: 'character', name: msg.who })[0];     var adjustment = parseInt(msg.content.replace("!steady ", ""));          if(playerChar){         sendChat(msg.who, "/em takes a moment to steady themself.");                  var ap = findObjs({ type: 'attribute', characterid: playerChar.id, name: "ap" })[0];         var apCurrent = parseInt(ap.get('current'));         apCurrent += adjustment;         ap.set('current', apCurrent);     }else{sendChat(msg.who, "Action Failed because I should be sending chat messages as my character!");}   } });
1599893770
GiGs
Pro
Sheet Author
API Scripter
I';m wondering if the original issue was due to javascripts handling of 0, which can also be treated as logical false in some cases. If there's some check against the attribute value, every other value would return true, but 0 would return false, and that might be causing it to fail.
1599906001
Jakob
Pro
Sheet Author
API Scripter
I pasted your literal character sheet code into a sheet and ran the macro you pasted as an ability on the character. It worked. There must be something else going on here: Maybe there are several characters with the same name (or close enough), and that's causing problems. It would try --charids @{character_id} instead of the character name, that's unique. Your script uses a completely different way of identifying the character based on the message. Maybe the character has several attributes with the same name, in which case only one of them would be changed. This should be the same one as in your script, though, so I don't think this is it. ??? No idea. If the script is sending a message that it is setting an attribute to 1, it is certainly setting something  to 1, it may not be the right attribute for some reason. the max should not come into play unless you use --modb/!modbattr.