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

[ChatSetAttr][5e Shaped] Adjusting Trait Charges (Current & Maximum)

1531652121

Edited 1531652642
I'm looking for a way to  adjust a character's trait's current charges , and while we're at it, to  change a traits maximum charges per day  (to update any changes that may have happened elsewhere - the total being related to a characters' total HP) I'm pitching at straws trying to  figure  out how to make those changes happen, what commands (@, ~, !, %) and syntax ( repeating_trait_$2_trait)   to use.  I've never really been able to get this script to output, and I think it's because I have no idea of some of the more complex concepts and keys. Here's the macro I tried to get working, but was told this isn't something the Shaped Sheet or Companion can access/ modify from macros/ chat, and that ChatSetAttr was.  However, without specific references (do this like this to make this happen) ... or a book named "ChatSetAttr for Dummies", I can't make heads or tails of it. /w gm &{template: 5e-shaped}{{title=Meter Adjustment}}{{Meter Change=[[?{What Form Are You Currently In?|Human,-|Hybrid,+}?{How many points were changed to your meter?|1|2|3|4})]]}} {{%{Volodar Ichor|repeating_trait_$2_trait|?{What Form Are You Currently In?|Human,-|Hybrid,+}?{How many points were changed to your meter?}}}} {{%{Volodar Ichor|repeating_trait_$2_trait|@{ Volodar Ichor|hp|max }}}} To walk you through the macro here, or rather, the desired effects : 1) It queries whether the character ( Volodar Ichor)  is in Human or Hybrid form, resulting in a - or + to the meter (EX: "+") 2) It asks how many points, given in a prior macro, were assessed.  (EX: "2") 3) It should (but doesn't) add or subtract from the 3rd trait's charges (Ex: "+2" to current 3rd trait charge) 4) Just a routine, it needs to check the character's maximum HP, and then update the maximum charges per day to that number.  This is to provide automated level change increases to that meter.  (Example: HP Max and Trait 3 Max Charges were at "10", but character gained a level and now HP Max is 16, Counter Max is still 10.  This changes maximum charges of trait 3 to 16.  Next run of the script it finds the charge at 16, it will make the max charge 16 again, but this has no real effect since the change isn't noticeable.) Wishlist (haven't even tried to do this stuff): -   If character trait 3 reaches zero, uncheck modifier 1, check modifier 2 & weapons 1 and 2 , flip token to 2nd pic .   - If character   trait 3  reaches counter maximum,  uncheck modifier 2, check modifier 1 , uncheck weapons 1 and 2, and , flip token to first pic. Looking for your help Jakob, you asked me to post here. ;-)
1531653810

Edited 1531654009
Jakob
Sheet Author
API Scripter
Okay, let me walk you through it. So, looking at the shaped sheet, the attribute for charged in the "trait" repeating section is called "uses", so in total you want to adjust the attribute "repeating_trait_$2_uses" and its maximum  (I'm not quite sure what you want to accomplish with the "%{Volodar Ichor|repeating_trait_$2_trait||...}" ability call, so I'm just going to ignore that as part of some failed attempt). To adjust an attribute relatively in ChatSetAttr, you can use either "!modattr" or "!modbattr" ... the difference is that the latter will bound the resulting value between 0 and the maximum. Choose whatever you like better, I will use "!modattr" for simplicity. You can change an attribute value with "--attrName|current|max" as ChatSetAttr option. ChatSetAttr needs a "target" switch in order to know which character to perform adjustments for. If you know a character's ID, you can just use "--charid ID" and plug in the character id for ID. If you're within an ability, it is easy to target yourself by "--charid @{character_id}". I'm assuming that this command is run as an ability from the attributes & abilities tab of a character. Some changes are necessary if it is a global macro.  In total, a ChatSetAttr command to do the things you're asking for would be the following, assuming you have the queries defined already in some earlier part of the macro. !modattr --charid @{character_id} --repeating_trait_$2_uses|?{What Form Are You Currently In?}?{How many points were changed to your meter?}|@{ hp|max } If we put this together with your chat macro, we get this: /w gm &{template: 5e-shaped} {{title=Meter Adjustment}} {{Meter Change=[[?{What Form Are You Currently In?|Human,-|Hybrid,+}?{How many points were changed to your meter?|1|2|3|4}]]}} !modattr --charid @{character_id} --repeating_trait_$2_uses|?{What Form Are You Currently In?}?{How many points were changed to your meter?}|@{hp|max} Up to maybe a typo or two, this should do it. EDIT:  Oh, and the wishlist stuff is somewhere between complicated and impossible (I think everything except for the token pic change should be possible, but using --evaluate may be necessary).
WOW! - I changed the reference to "--name Volodar Ichor" since it is from the macro menu (global macro, i'm guessing?) and it worked.  However, there is no define only as the HP, so it increases by the Max HP amount every time the script is run, instead of flat defining the value, so I gave it a moment of thought and figured the difference between modifying and setting, so I omitted a modifier for the HP check, and placed it in a SetAttr command instead /w gm &{template: 5e-shaped} {{title=Meter Adjustment}} {{Meter Change=[[?{What Form Are You Currently In?|Human,-|Hybrid,+}?{How many points were changed to your meter?|1|2|3|4}]]}} !modattr --name Volodar Ichor --repeating_trait_$2_uses|?{What Form Are You Currently In?}?{How many points were changed to your meter?}| !setattr --name Volodar Ichor --repeating_trait_$2_uses||@{Volodar Ichor|hp|max} I think --modbattr might be better, as I noticed that the current can drop below 0, and above maximum.  If I need anything other than changing the call to go with that, let me know before I do it. Only thing is that I don't think I have the setup right for transmitting the max HP value to the API.  @{Volodar Ichor|hp|max} works in the chat window to give me the correct number for HP, but it won't be seen as a number to the API for whatever reason.  Throws this error for that part ( !setattr --name Volodar Ichor --repeating_trait_$2_uses||@{Volodar Ichor|hp|max}) :  (From ChatSetAttr): Errors Attribute maximum repeating_trait_$2_uses is not number-valued for character Volodar Ichor. Attribute maximum left unchanged. Okay, let me walk you through it. So, looking at the shaped sheet, the attribute for charged in the "trait" repeating section is called "uses", so in total you want to adjust the attribute "repeating_trait_$2_uses" and its maximum  (I'm not quite sure what you want to accomplish with the "%{Volodar Ichor|repeating_trait_$2_trait||...}" ability call, so I'm just going to ignore that as part of some failed attempt). To adjust an attribute relatively in ChatSetAttr, you can use either "!modattr" or "!modbattr" ... the difference is that the latter will bound the resulting value between 0 and the maximum. Choose whatever you like better, I will use "!modattr" for simplicity. You can change an attribute value with "--attrName|current|max" as ChatSetAttr option. ChatSetAttr needs a "target" switch in order to know which character to perform adjustments for. If you know a character's ID, you can just use "--charid ID" and plug in the character id for ID. If you're within an ability, it is easy to target yourself by "--charid @{character_id}". I'm assuming that this command is run as an ability from the attributes & abilities tab of a character. Some changes are necessary if it is a global macro.  In total, a ChatSetAttr command to do the things you're asking for would be the following, assuming you have the queries defined already in some earlier part of the macro. !modattr --charid @{character_id} --repeating_trait_$2_uses|?{What Form Are You Currently In?}?{How many points were changed to your meter?}|@{ hp|max } If we put this together with your chat macro, we get this: /w gm &{template: 5e-shaped} {{title=Meter Adjustment}} {{Meter Change=[[?{What Form Are You Currently In?|Human,-|Hybrid,+}?{How many points were changed to your meter?|1|2|3|4}]]}} !modattr --charid @{character_id} --repeating_trait_$2_uses|?{What Form Are You Currently In?}?{How many points were changed to your meter?}|@{hp|max} Up to maybe a typo or two, this should do it. EDIT:  Oh, and the wishlist stuff is somewhere between complicated and impossible (I think everything except for the token pic change should be possible, but using --evaluate may be necessary).
ok this is weird ... sometimes it works ... "-ish": (From ChatSetAttr): Errors Attribute maximum repeating_trait_$2_uses is not number-valued for character Volodar Ichor. Attribute maximum left unchanged. 8:07AM (From ChatSetAttr): Setting attributes Setting repeating_trait_$2_uses to 7 for character Volodar Ichor. 8:07AM (From ChatSetAttr): Setting attributes Setting repeating_trait_$2_uses to 9 (max) for character Volodar Ichor. but sometimes it doesn't: 8:07AM (From ChatSetAttr): Errors Attribute maximum repeating_trait_$2_uses is not number-valued for character Volodar Ichor. Attribute maximum left unchanged. 8:07AM (From ChatSetAttr): Setting attributes Setting repeating_trait_$2_uses to 8 for character Volodar Ichor.
Seems to work every 3rd hit
1531657736
Jakob
Sheet Author
API Scripter
Good thinking with not modifying, but setting the maximum. That was a brain fart on my side. You should probably omit the final vertical line if you do not intend to set the max to get better behaviour: !modbattr --name Volodar Ichor --repeating_trait_$2_uses|?{What Form Are You Currently In?}?{How many points were changed to your meter?} !setattr --name Volodar Ichor --repeating_trait_$2_uses||@{Volodar Ichor|hp|max}
--modbattr works perfectly at keeping things in the appropriate range.  Now if only we could get it to know when it hits 0 or max, to do other things ... and also get rid of that error message by setting up the reference received as a number...
Jakob said: Good thinking with not modifying, but setting the maximum. That was a brain fart on my side. You should probably omit the final vertical line if you do not intend to set the max to get better behaviour: !modbattr --name Volodar Ichor --repeating_trait_$2_uses|?{What Form Are You Currently In?}?{How many points were changed to your meter?} !setattr --name Volodar Ichor --repeating_trait_$2_uses||@{Volodar Ichor|hp|max} will do
1531658267

Edited 1531658361
Doing this /w gm ?{What Form Are You Currently In?|Human,-|Hybrid,+}?{How many points were changed to your meter?|1|2|3|4} !modbattr --name Volodar Ichor --repeating_trait_$2_uses|?{What Form Are You Currently In?}?{How many points were changed to your meter?} !setattr --name Volodar Ichor --repeating_trait_$2_uses||@{Volodar Ichor|hp|max} !setattr --name Volodar Ichor --repeating_trait_$2_uses||@{Volodar Ichor|hp|max} !setattr --name Volodar Ichor --repeating_trait_$2_uses||@{Volodar Ichor|hp|max} is helping to push the error through, but it seems so unclean to have to do it that way.  Is there a way to make the API know that it's getting a number?  I remember in Javascript there was a code when this was a problem; something like "Num(var)".  I know this would absolutely not work, but if I was right, then the code would be - if it weren't parsed -  !setattr --name Volodar Ichor --repeating_trait_$2_uses||Num(@{Volodar Ichor|hp|max})
Actually - that extra pipe was the whole reason for the NaN error ... once I tested it again, no error.   So now how do we know when the meter reaches 0 or MAX values, and change the token?  You said something about evaluate?
1531665360

Edited 1531665529
So I did set up something in another macro to work for changing the modifiers section, that works !setattr --silent --name Volodar Ichor --repeating_modifier_$0_active#0 !setattr --silent --name Volodar Ichor --repeating_modifier_$1_active#1 and it's inverse !setattr --silent --name Volodar Ichor --repeating_modifier_$0_active#0 !setattr --silent --name Volodar Ichor --repeating_modifier_$1_active#1 But I can't toggle the weapons off and on (this didn't work): !setattr --name Volodar Ichor --repeating_offense_$0 _active#1 !setattr --name Volodar Ichor --repeating_offense_$1 _active#1 inverse !setattr --name Volodar Ichor --repeating_offense_$0 _active#0 !setattr --name Volodar Ichor --repeating_offense_$1 _active#0 Also, still waiting on changing a multi-sided token - that one I have no idea how to manipulate.  Or a way to check that trait's current state of 0 or MAX to fire these changes.
1531673889
Jakob
Sheet Author
API Scripter
The weapon checkbox probably has a different attribute value for it's "checked" status rather than 1 - it would be necessary to investigate on the sheet what exactly it is. Once you know the correct value, it should work exactly as for the modifier. You can combine two attributes in one command:  !setattr --silent --name Volodar Ichor --repeating_modifier_$0_active#1 --repeating_modifier_$1_active#1 About the multi-sided token, that would be a TokenMod command. Firing it conditionally is not possible within this framework, however. Doing this stuff conditionally on the value being 0 or max would be some serious work. I don't have the time to look into this right now, sorry.
It's ok - you've been a huge help already!!!  TYVM! Where can I find a list of attribute values and command/action phrases?  In other words, this part of the line:  repeating_modifier_$0_ active#1
1531738718
Jakob
Sheet Author
API Scripter
Wolf Thunderspirit said: It's ok - you've been a huge help already!!!  TYVM! Where can I find a list of attribute values and command/action phrases?  In other words, this part of the line:  repeating_modifier_$0_ active#1 You will have to inspect the inputs on the character sheet. (right click -> "inspect" or "inspect element", depending on Chrome or Firefox). For checkboxes in particular (like in this example), they will have a "name" attribute, in this case `name="attr_uses"`, and a "value" attribute, in this case `value="1"`. The content of name, without the attr_, is the attribute name (with the repeating stuff tacked on in front if it is a repeating attribute), and the content of value is the value of the attribute when the checkbox is ticked. When unticked, the value is always 0.
gotcha ... tyvm Jakob.  I'm still having issues getting players to be able to use their own setattr commands, though I can work them perfectly fine.  Even CoGM has issues.  Seems like I'm the only one that can do anything, and not always all the time (that part - I think - is operator error)
1531803568
Jakob
Sheet Author
API Scripter
Any player should be able to set values for any character they control, so I don't know what's up there. In particular, a Co-GM (when logged in as a GM) will have all the same rights that you do.
1531808770

Edited 1531808815
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
If you want to do some testing and don't want to have to wait until your players are available, or aren't sure of their technical acumen, you can create a dummy account and invite it to your game as a player. Log into it using a different browser or in a private browsing window and you can be player and GM at the same time. It can really speed up testing issues like this.
1531860738

Edited 1531860765
ALOT of the errors I've had with scripts has been a misunderstanding about using the one-click install and happening across archived versions, as discovered last night by TheAaron regarding tokenmod.  I think he said I was using a 2015 version, which he only discovered via being in my game as a GM. Where I got lost was the Companion script the the character sheet, which pretty much says 'don't ever load me from one-click unless you want to meet your doom' Ok ... that was an exaggeration ... lol.  But the issue I had was thinking, ok, the one-click is for the lazy, I should load ALL my scripts from github.  Aaron explained it to me.  *sigh* my dumb ... So I'm going to start working with my scripts today and see if it's changed my world (or at least brought me up to 2018)
I think my stupidity should send a signal to you great coders out there though.  First question to ask: What version are you running?
The weapon checkbox probably has a different attribute value for it's "checked" status rather than 1 - it would be necessary to investigate on the sheet what exactly it is. Once you know the correct value, it should work exactly as for the modifier. You can combine two attributes in one command:  !setattr --silent --name Volodar Ichor --repeating_modifier_$0_active#1 --repeating_modifier_$1_active#1 About the multi-sided token, that would be a TokenMod command. Firing it conditionally is not possible within this framework, however. Doing this stuff conditionally on the value being 0 or max would be some serious work. I don't have the time to look into this right now, sorry. I've set up some death save logic that was toggling the death save checkboxes, on the OGL sheet.  The value for when the box is checked is "on" and when its not, "0".  I would have thought it more like a boolean, but I guess not.  I'm not sure what the values would be for other sheets though.