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

Adding a "_max" value to an attribute

I have the following sheetworker which creates the attribute called "body"     on('change:bodyxp sheet:opened', function () {         getAttrs(['bodyxp'], function(v) {             const bodyxp = v.bodyxp *1||0;             const body = Math.round(bodyxp/2 + 10);             setAttrs({                 body: body             });         });     }); My question is...how do I add a "_max" value to this sheetworker?
1562423237
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Do you want to set a max on the sheet, like you have 200 out of 400 body? Or do you want to limit the value to a maximum, or of course both? For the first one, you'd just add it to your setattrs: on('change:bodyxp sheet:opened', function () {         getAttrs(['bodyxp'], function(v) {             const bodyxp = v.bodyxp *1||0;             const body = Math.round(bodyxp/2 + 10);             setAttrs({                 body: body,                  body_max:100             });         });     }); For the second you'd use Math.min or _.min (depending on coding needs) to limit the calculation to an upper bound. You could also use Math.max or _.max to limit it to a lower boundary as well.
1562429596
GiGs
Pro
Sheet Author
API Scripter
Since I know you are playing hero system, I suspect you want body max set instead of body, you could do setAttrs({                 body_max: body,             }); Then have a different routine for checking when body_max changes and altering body's current value if its needed.  It would be a good to idea to have a rest button, that sets all stats to their max value. If you do  setAttrs({                 body: body,                  body_max: body             }); There'll be a minor problem. When a player spends points to buy up their body, their current and max will both increase. This is only an issue if you allow experience spending in mid-adventure. Say a character has a body score of 15. He takes ten damage, so now has a body_max of 15 and a body of 5. He then spends 2 points and increases Body by 1. His body and body_max will both immediately jump to 16, whereas you probably want body to go to 6, and body_max to 16. As I said, this is only an issue if you allow changing XP before healing, which probably isn't going to happen, but I thought I'd mention it in case.
Scott C. said: Do you want to set a max on the sheet, like you have 200 out of 400 body? Or do you want to limit the value to a maximum, or of course both? For the first one, you'd just add it to your setattrs: on('change:bodyxp sheet:opened', function () {         getAttrs(['bodyxp'], function(v) {             const bodyxp = v.bodyxp *1||0;             const body = Math.round(bodyxp/2 + 10);             setAttrs({                 body: body,                  body_max:100             });         });     }); For the second you'd use Math.min or _.min (depending on coding needs) to limit the calculation to an upper bound. You could also use Math.max or _.max to limit it to a lower boundary as well. Scott C. said: Do you want to set a max on the sheet, like you have 200 out of 400 body? Or do you want to limit the value to a maximum, or of course both? For the first one, you'd just add it to your setattrs: on('change:bodyxp sheet:opened', function () {         getAttrs(['bodyxp'], function(v) {             const bodyxp = v.bodyxp *1||0;             const body = Math.round(bodyxp/2 + 10);             setAttrs({                 body: body,                  body_max:100             });         });     }); For the second you'd use Math.min or _.min (depending on coding needs) to limit the calculation to an upper bound. You could also use Math.max or _.max to limit it to a lower boundary as well. Thanks Scott...the Math.max and Math.min look useful...I will see how that goes  :)
GiGs said: Since I know you are playing hero system, I suspect you want body max set instead of body, you could do setAttrs({                 body_max: body,             }); Then have a different routine for checking when body_max changes and altering body's current value if its needed.  It would be a good to idea to have a rest button, that sets all stats to their max value. If you do  setAttrs({                 body: body,                  body_max: body             }); There'll be a minor problem. When a player spends points to buy up their body, their current and max will both increase. This is only an issue if you allow experience spending in mid-adventure. Say a character has a body score of 15. He takes ten damage, so now has a body_max of 15 and a body of 5. He then spends 2 points and increases Body by 1. His body and body_max will both immediately jump to 16, whereas you probably want body to go to 6, and body_max to 16. As I said, this is only an issue if you allow changing XP before healing, which probably isn't going to happen, but I thought I'd mention it in case. Thanks GiGs...understood...as always, you are a legend  :)
1562449868
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hero System? Which edition? Asking for a friend named keithcurtis.
1562450383
GiGs
Pro
Sheet Author
API Scripter
4th, based on my recollection of early threads :)
1562450676
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Ah. I have a huge investment in 5th Edition. As in, every book.
keithcurtis said: Hero System? Which edition? Asking for a friend named keithcurtis. Hero 4th edition, amalgamated with some parts of Fantasy Hero 5th.
Ok...for the collective group-think...can anyone point me to a list of the sheetworker event triggers? Currently I am only familiar with "sheet:opened" and "change:foo" I had a look on the wiki, but the link goes nowhere...
1562539351

Edited 1562539367
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
That's pretty much it. The only other one is clicked:foo, which only listens to <button type='action' name='act_foo'>. Note that this is NOT  the same as a roll button.
Scott C. said: That's pretty much it. The only other one is clicked:foo, which only listens to <button type='action' name='act_foo'>. Note that this is NOT  the same as a roll button. Thanks Scott.  :)
1562539639
Andreas J.
Forum Champion
Sheet Author
Translator
The Sheetworkers wiki page mentions: change:<attribute_name> remove:repeating_<groupname> sheet:opened clicked:<button_name>
1562539750
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Ah, I always forget about remove, thanks andreas.
1562539930

Edited 1562540065
Ray
Pro
Scott C. said: Ah, I always forget about remove, thanks andreas. Remove? What does that do? (errr....what I mean to say is, what is the functionality of that command) Stupid question....II will get off my lazy ass and read it for myself  :P
1562540413
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Remove allows you to react to a repeating row being removed. Useful for keeping something like a weight carried field updated when an equipment item gets removed