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 Question—Keeping current value if it's greater

So here's some examples of what I'm trying to do: A command that increases a bonus value by 2, but will not raise it above 2, and will not decrease it to 2 if it's already 3 or greater A command that decreases a bonus value by 1, but will not lower it below –1, and will not raise it to –1 if it's already –2 or lesser I feel like there's a way to calculate this using the script's --evaluate function (allows math using existing sheet attributes), but I'm having a rough time figuring out how to accomplish this. Any suggestions/solutions are greatly appreciated!
1586150780
GiGs
Pro
Sheet Author
API Scripter
Those are very complex conditionals. I'd normally have to create a separate api script for that. I cant find much documentation on using evaluate, is tehre any? All I know is it can use ternary operators, so you might be able to do this with nested ternaries. It's also hard to answer this without knowing how the bonus value is being calculated. What attributes are your changing? So this post is just flailing wildly into the dark. That said, the first evaluate command might look something like --attr1|("%attr1%" >= 3) ? "%attr1%" : Math.min(2, "%attr1%" + bonus) If its a dice roll, you can use dh / kl in place of Math.min, and might have to - i dont know if that works with evaluate.  and the second --attr1|("%attr1%" <= -1) ? "%attr1%" : Math.max(-1, "%attr1%" + bonus)
1586155169

Edited 1586155659
Thanks for taking a crack at it! Sorry, I'll try to explain better: In PF2e, bonuses that share a type do not stack; the best one is applied. If a character has three effects on their armor class—a +1 status bonus, a +2 status bonus, and a +1 circumstance bonus—the +2 status bonus overrides the +1 status bonus while stacking with the +1 circumstance bonus, resulting in a total bonus of +3. Same goes for typed penalties: the worst is applied. But penalties and bonuses of the same type overlap, so a +1 status bonus and a –2 status penalty would result in a –1 status penalty. I'm trying to set up macros to apply common bonuses and penalties, such as from spells or conditions, but currently I can't find a way to account for ones that can't stack. So if a character already has bonus of +2 in their status modifier for armor class (default value of the modifier is 0), and they get another buff that provides a +1 status bonus, they would end up with a +3 when ought to be a +2. But if that same character instead got a condition that applied a –1 status penalty, they should end up with a +1 bonus. The only mention of --evaluate I can find is this: --evaluate is a GM-only (unless you allow it to be used by players via the configuration) option that will use JavaScript eval() to evaluate the attribute value expressions. This allows you to do math in expressions involving other attributes (see the example below). However, this option is inherently dangerous and prone to errors, so be careful. [...] If the current value of attr1 is 3 and the current value of attr2 is 2, !setattr --sel --evaluate --attr3|2*%attr1% + 7 - %attr2% will set the current value of attr3 to 15. I also realized it would need to be a command to replace the value, rather than modify it, as some of the attribute fields are not number-valued. I tested the following !modattr --sel --evaluate --armor_class_temporary|("%armor_class_temporary%" >= 3) ? "%armor_class_temporary%" : Math.min(2, "%armor_class_temporary%" + ?{Status Bonus}) and got Changing it from !modattr to !setattr resulted in this:
1586156172

Edited 1586156202
GiGs
Pro
Sheet Author
API Scripter
What a confusing error. what exactly does armor_class_temporary contain? It's hard to tell from the character sheet, and i dont see a reference to it in the sheet worker code so its probably being constructed in parts. Honestly i think the only way you could do this reliably is with a dedicated script. But yu would need to know the format armor_class_temporary expects.
1586161662

Edited 1586162838
It's a text field but it's intended to only contain a number value that modifies the total AC, so normally !setattr would work for it, but !modattr doesn't because it's a text field. Right now I can set it to –1 or 2 or any other integer no problem, but if there's already a value there I can only replace it, hence why I hoped to figure out a way to automatically calculate the appropriate change before setting it with a new value. EDIT: I was wrong, !modattr works just fine on it... Anyway, so I can get this to work fine for the most part !setattr --sel --evaluate --armor_class_temporary|Math.max(-1, "%armor_class_temporary%" - 1) but if the value is already set to, say, –3, it changes it to –1
But I think I'm out of my depth, because if the attribute already had something like –2 and +5 applied, for a total of +3, I wouldn't have a way to compare a –1 penalty to the already existing –2, and it would end up changing to a +2... Thanks for helping me look into this anyway, GiGs! Gonna have to stick to manual tracking for now, though.
1586163532
GiGs
Pro
Sheet Author
API Scripter
Persephone said: Anyway, so I can get this to work fine for the most part !setattr --sel --evaluate --armor_class_temporary|Math.max(-1, "%armor_class_temporary%" - 1) but if the value is already set to, say, –3, it changes it to –1 What about !setattr --sel --evaluate --armor_class_temporary|(("%armor_class_temporary%" <= -1) ? "%armor_class_temporary%" : Math.max("%armor_class_temporary%", "%armor_class_temporary%" - 1)) Also, if evaluate supports javascript, you might be able to use parseInt in there to make sure they are used as numbers.
1586163587
GiGs
Pro
Sheet Author
API Scripter
Persephone said: But I think I'm out of my depth, because if the attribute already had something like –2 and +5 applied, for a total of +3, I wouldn't have a way to compare a –1 penalty to the already existing –2, and it would end up changing to a +2... Thanks for helping me look into this anyway, GiGs! Gonna have to stick to manual tracking for now, though. Yes, that does seem to make it impossible, unless you were able to analyse every bonus in the sheet.
1586192292

Edited 1586192393
Dumbhuman
Pro
Marketplace Creator
Persephone said: But I think I'm out of my depth, because if the attribute already had something like –2 and +5 applied, for a total of +3, I wouldn't have a way to compare a –1 penalty to the already existing –2, and it would end up changing to a +2... Thanks for helping me look into this anyway, GiGs! Gonna have to stick to manual tracking for now, though. It sounds like you might want to create attributes to serve as variables storing the current negative bonus and current positive bonus rather than just the final total bonus being applied.  That way you'll be able to to use evaluate to compare the bonus you want to apply to the current bonus and only execute operations if it satisfies your conditions.  Be sure to expressly set each attribute involved in the evaluate operation to a number first (likely 0 for the new ones you create), otherwise you'll likely get the "is not number-valued" error messages which will pop up with the same wording if the value you're adding isn't considered a number even if the attribute you're adding to is. You might be able to glean some more insights from this thread where Jakob helped me sort out some evaluate problems.
I just thought of that same thing and was about to share! lol Thanks, KC, I'll take a look at that thread. I'm gonna try this: a macro to create new attributes for all PC sheets, like !setattr {{ --sel --ac_statbonus|0 --ac_statpen|0 --ac_circbonus|0 --ac_circpen|0 --global_skill_statbonus|0 --global_skill_statpen|0 [etc...] }} then a macro to apply those attributes in the relevant notes, like !setattr {{ --sel --replace --armor_class_notes|**MODIFIER** <<(`{ac_statbonus}-`{ac_statpen}) + (`{ac_circbonus}-`{ac_circpen})>> --acrobatics_notes|**MODIFIER** <<(`{global_skill_statbonus}-`{global_skill_statpen}) + (`{global_skill_circbonus}-`{global_skill_circpen})>> [etc...] }} then I think I'll only have to worry about this syntax for all commands that modify those abilities, whether they're penalties or bonuses, like !setattr --sel --evaluate --ac_statbonus|Math.min( bonus , "%ac_statbonus%" + bonus )