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 no lower than 0

Is there a way to have chatsetattr stop reducing values below 0?
1619722378
timmaugh
Pro
API Scripter
Does your macro rely in decrementing? Or calculations that result in a number that then gets applied/used in the ChatSetAttr call? Here's an inline solution using MathOps, demonstrating decrementing an arrows value and stopping at 0: {& math max(0, @{Archelena|arrows} - 1) } Or, using Fetch, too, you can supply a default value for the attribute if it doesn't exist: {& math max(0, @(Archelena.arrows[0]) - 1) } What does a typical macro look like where ChatSetAttr tries to reduce a value below 0?
!serattr --sel --arrows|-1
1619728030
timmaugh
Pro
API Scripter
Yep, so someone may be able to come along and tell you more about a built-in limiter for ChatSetAttr, but until then I think you can do basically what I mentioned, above, provided the -1 is a trigger to CSA to decrement, and we can skip that by just supplying a value. Grab MathOps, SelectManager, and ZeroFrame and get them installed. If you want to default a value in as a starting point if the attribute isn't found, grab Fetch, too. (I know ChatSetAttr creates and sets the attribute if it doesn't exist; but we need it sooner than that. Using an @{selected} call will stop your macro before it even gets there... but Fetch with a default value will let you proceed.) !setattr --sel --arrows|{&math max(0,@{selected|arrows}-1)} Here's the alternate version using the Fetch construction instead of the Roll20 @{selected...}... !setattr --sel --arrows|{&math max(0,@(selected.arrows[0])-1)} Make sure you have SelectManager set to restore selected tokens automatically, since your setattr call will now require that. (If you have a question about that, post back). Lastly, with ZeroFrame the above should resolve in no matter what order the other scripts are designated to run (MathOps before Fetch or Fetch before MathOps)... the former will just take one more loop cycle as MathOps will tell ZeroFrame "...huh?..." the first time, and only be able to do the math once it knows what Fetch has returned (after the first pass). If you want to force the order to go Fetch=>MathOps, you can put the following element in your line somewhere (like at the end): {&0 fetch math}
ChatSetAttr has a built in way to do it, just use !modbattr --sel --arrows|-1
1619744950
Chatsetattr not going below 0 would be "Battr" for each command.  modbattr, setbattr.  Fair warning, it will NOT warn you that its falsely succeeding when it reduces 0 to 0.  I believe it will also not go over the maximum either.  
Thanks Persephone and DM Eddie. Those worked perfectly.