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 Help

I was wondering how to subtract one until it reaches 0 This is a custom sheet BTW Here is my code !modattr --silent --name @{character_name} --exhaustion_status|[[@{exhaustion_status}-1]]!!!  It works fine but always goes below 0 and i would like it to stop at 0. I tried using the !modbattr but for some reason it always uses the max value instead of 0 to max like description says.
<a href="https://app.roll20.net/forum/post/10029701/chatsetattr-no-lower-than-0/?pageforid=10029701#post-10029701" rel="nofollow">https://app.roll20.net/forum/post/10029701/chatsetattr-no-lower-than-0/?pageforid=10029701#post-10029701</a>
1643846127

Edited 1643846757
K figured out my issue was im trying to use both !setattr and !modbattr in same line of code it its ignoring my second one.&nbsp; Thoughts? ***Update figured it out needed to use --modb instead of starting a new !modbattr
1643900535

Edited 1643900685
Andreas J.
Forum Champion
Sheet Author
Translator
Rouse said: ***Update figured it out needed to use --modb instead of starting a new !modbattr Can you post here how the final command turned out? (and showing the code like this makes it more clear btw:
Well I spoke to soon it works but part of the code shows up in the chat window.&nbsp; The code works and does what i want but not the correct way. I had to return the button code to get it to work, im still a noob when comes to coding.&nbsp; I know your suppose to leave button code all on same line.&nbsp; Im up for any suggestions!!!! Please. When i put them in the same line like we are suppose to the second !modbattr is ignored.&nbsp; I tried --modb for the second one but it still doesnt function as intended.&nbsp; I know there is a Long Rest API already but its not for my custom "Modded" sheet (5e Community Contributed), since i dont know how to code the API, i was working on something i understand a little more. I tried removing the first end of Code String (!!!) to see if that was my problem but the same results. &lt;button type="roll" class="sheet-roll" name="roll_Long_Rest" value="&amp;{template:5eDefault} {{character_name=@{character_name}}} {{title=Long Rest}} {{subheader=@{character_name}}} {{simple=1}} {{freetextname=@{character_name}}} {{freetext=Has taken a long rest. Max HP restored, Spell Slots reset to 0, Temp HP reset to 0, Place Holder..}} !setattr --name @{character_name} --spell_slots_l1|0 --spell_slots_l2|0 --spell_slots_l3|0 --spell_slots_l4|0 --spell_slots_l5|0 --spell_slots_l6|0 --spell_slots_l7|0 --spell_slots_l8|0 --spell_slots_l9|0 --hp|@{hp|max} --temp_HP|0!!! !modbattr --name @{character_name} --exhaustion_status|-1!!!"&gt; Take Long Rest&lt;/button&gt;
Fwiw I find that modb and other bindings to 0-max typically are counterintuitive.&nbsp; I actually want to see that they have gone negative so I know the players out of them.&nbsp; The API response when its modding nothing does not reveal that.&nbsp; So a player can be at 0 level 1 spell slots left but the chatsetattr command will say its reducing slots by 1 to 0 even though it went 0 to 0.&nbsp; Its actually ok to go negative and inform you that they are out that way.&nbsp; When api's like resting in style&nbsp; fire they will reset the negative to the max.&nbsp;&nbsp;
DM Eddie said: Fwiw I find that modb and other bindings to 0-max typically are counterintuitive.&nbsp; I actually want to see that they have gone negative so I know the players out of them.&nbsp; The API response when its modding nothing does not reveal that.&nbsp; So a player can be at 0 level 1 spell slots left but the chatsetattr command will say its reducing slots by 1 to 0 even though it went 0 to 0.&nbsp; Its actually ok to go negative and inform you that they are out that way.&nbsp; When api's like resting in style&nbsp; fire they will reset the negative to the max.&nbsp;&nbsp; The one im having issue with is a Exhaustion level, Zero being none and 6 death.&nbsp; I want it to stay at Zero and not go negative so my None box stays checked.&nbsp; I totally agree with your about showing negative, but in this instance I want the Zero to stay set to Zero.
1643916321

Edited 1643916681
Andreas J.
Forum Champion
Sheet Author
Translator
I tried --modb for the second one but it still doesnt function as intended. What does it do then? Does it not work at all, or changes the value in some other way? Maybe --mod is what you intended, not --modb ? The readme on github have some stuff that isn't mentioned on the wiki page: <a href="https://github.com/Roll20/roll20-api-scripts/tree/master/ChatSetAttr#readme" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/tree/master/ChatSetAttr#readme</a> <a href="https://wiki.roll20.net/Script:ChatSetAttr" rel="nofollow">https://wiki.roll20.net/Script:ChatSetAttr</a>
1643916482
David M.
Pro
API Scripter
From the documentation: --modb &nbsp;works like&nbsp; --mod , except that the attribute's current value is kept between 0 and its maximum. You can use&nbsp; !modbattr &nbsp;as a shortcut for&nbsp; !setattr --modb .
1643917193

Edited 1643918745
&lt;button type="roll" class="sheet-roll" name="roll_Long_Rest" value="&amp;{template:5eDefault} {{character_name=@{character_name}}} {{title=Long Rest}} {{subheader=@{character_name}}} {{simple=1}} {{freetextname=@{character_name}}} {{freetext=Has taken a long rest. Max HP restored, Spell Slots reset to 0, Temp HP reset to 0, Others Here}} !setattr --name @{character_name} --spell_slots_l1|0 --spell_slots_l2|0 --spell_slots_l3|0 --spell_slots_l4|0 --spell_slots_l5|0 --spell_slots_l6|0 --spell_slots_l7|0 --spell_slots_l8|0 --spell_slots_l9|0 --hp|@{hp|max} --temp_HP|0 --modb --exhaustion_status|-1!!!"&gt; Take Long Rest&lt;/button&gt; So setting the code like above all in a single line and using --modb&nbsp; everything infront of it doesnt do anything except --hp|@{hp|max}&nbsp; everything after the --modb works like a charm like its suppose to. Its like it ignores the first Setattr and only using the --modb which the --hp|@{hp|max} can work on it as well. But if i break the button code into 2 separate lines with in the code both work, but i get this Update - I think im just going to change it to all work from a Macro.&nbsp; Seems to work fine.
Isn't there a long standing issue with selected/target calls and multiple api commands?&nbsp; Sometimes randomly it will ignore the second command?
1643979818
timmaugh
Pro
API Scripter
There is a bug where Roll20 drops commands , but the one I'm aware of does not require selected/targeted interaction. As well, I'm not sure it would apply to Rouse's last example, as that one had everything in a single command. Can yo tell us... Are the spell slots repeating attributes or standard attributes? Because the ones that look like they work seem like they are standard attributes, for sure.
Is there a way to use this in a macro in a way that, the macro inputs a spell level and that spell slot is depleted by 1
1647752133

Edited 1647752161
So this is how i coded it into the 5e Community Sheet , you will need to alter --name @{character_name} --spell_slots_1 to match your sheet attributes you are using. You will also want to change the 1!!! to -1!!! !modattr --silent --name @{character_name} --spell_slots_l?{Cast at what level?|Level 2,2|Level 3,3|Level 4,4|Level 5,5|Level 6,6|Level 7,7|Level 8,8|Level 9,9}|1!!!