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

Trying to modify a value by an Attribute

1712879184

Edited 1712879225
Hey all, I have melee weapons in my system, and I'm hoping that the damage they do is modified by the Body Attribute of the character. This is the HTML for the Attribute: <th bgcolor="#F5B7B1">Body:</th> <td bgcolor="#F5B7B1"> <input type="number" name="attr_body" min="0"> <button type="roll" title="Roll against Body" value="!continuum body|@{body}|[[ ?{Modifiers not including IP|0} - @{IPTOTal}]]"></button> </td> And this is the script worker thingy for the Melee Weapons: on("change:repeating_meleeWeapons:meleeweaponrating change:repeating_meleeWeapons:meleeweapontype", function() { getAttrs(["repeating_meleeweapons_MeleeWeaponRating", "repeating_meleeweapons_MeleeWeaponType"], function(values) { let rating = parseInt(values.repeating_meleeweapons_MeleeWeaponRating) ||0; let damaged = Math.round(rating * 0.25); let damagec = Math.round(rating * 0.5); let damageb = Math.round(rating * 0.75); let damagea = Math.round(rating); const meleeWeapons = { none: {meleedamaged: 0, meleedamagec: 0, meleedamageb: 0, meleedamagea: 0}, Knife: {meleedamaged: (damaged + 1), meleedamagec: (damagec + 1), meleedamageb: (damageb + 1), meleedamagea: (damagea + 1)}, Sword_small: {meleedamaged: (damaged + 2), meleedamagec: (damagec + 2), meleedamageb: (damageb + 2), meleedamagea: (damagea + 2)}, Sword_medium: {meleedamaged: (damaged + 3), meleedamagec: (damagec + 3), meleedamageb: (damageb + 3), meleedamagea: (damagea + 3)}, Sword_large: {meleedamaged: (damaged + 4), meleedamagec: (damagec + 4), meleedamageb: (damageb + 4), meleedamagea: (damagea + 4)}, Club: {meleedamaged: (damaged + 1), meleedamagec: (damagec + 1), meleedamageb: (damageb + 1), meleedamagea: (damagea + 1)}, Staff: {meleedamaged: (damaged + 2), meleedamagec: (damagec + 2), meleedamageb: (damageb + 2), meleedamagea: (damagea + 2)}, Spear: {meleedamaged: (damaged + 3), meleedamagec: (damagec + 3), meleedamageb: (damageb + 3), meleedamagea: (damagea + 3)}, Polearm: {meleedamaged: (damaged + 4), meleedamagec: (damagec + 4), meleedamageb: (damageb + 4), meleedamagea: (damagea + 4)} }; const MeleeWeaponType = values.MeleeWeaponType; //make a temp variable called "RangedWeaponTypeValue" and store the value of RangedWeaponType in it. If not selected, 0 const thisMeleeWeapon = meleeWeapons[values.repeating_meleeweapons_MeleeWeaponType] || meleeweapons['none']; setAttrs({ "repeating_meleeWeapons_MeleeDamageD": thisMeleeWeapon.meleedamaged, "repeating_meleeWeapons_MeleeDamageC": thisMeleeWeapon.meleedamagec, "repeating_meleeWeapons_MeleeDamageB": thisMeleeWeapon.meleedamageb, "repeating_meleeWeapons_MeleeDamageA": thisMeleeWeapon.meleedamagea }); }); }); Ideally I'd like the value in Body to be added to the "rating" variable. Does anyone know the syntax for doing that? and yes, I know I shouldn't be using tables. Yell at me later.
1712895717
GiGs
Pro
Sheet Author
API Scripter
Are you asking for something like this? getAttrs(["body", "repeating_meleeweapons_MeleeWeaponRating", "repeating_meleeweapons_MeleeWeaponType"], function(values) { let rating = parseInt(values.repeating_meleeweapons_MeleeWeaponRating) ||0; let body = parseInt(values.body) ||0; rating += body; You should have it respond to changes in body too, but you are using the row id syntax here. If bpdy changes, it will affect every row in the repeating section, so you'd need to use the getSectionIDs method. I can show you how to adapt the code for that, but need to know if I'm understanding what you mean with the body + rating first (is code above what you need?).
1712895926

Edited 1712895998
GiGs
Pro
Sheet Author
API Scripter
By the way you should change this line on("change:repeating_meleeWeapons:meleeweaponrating change:repeating_meleeWeapons:meleeweapontype", function() { to on("change:repeating_meleeweapons:meleeweaponrating change:repeating_meleeweapons:meleeweapontype", function() { (This is all lower case on the event line). This not a "it would be nice if you to do this" kind of suggestion - it's "your code will break at some point in the future unless you do this." The event line must in lower case. The rest of the code can be left as is - but event lines must be all in lower case, no matter what the original case of the attributes is.
Thanks once again for the amazing tip GiGs. I'll make those changes.
I tried your suggested code, but all it seemed to do was stop the on change function from having any effect. Now the weapon damage values neither load nor change. I've been working in a copy of the (mostly) functional game, so nothing's broken.
1712906581

Edited 1712906823
GiGs
Pro
Sheet Author
API Scripter
Does the sheet work properly if you revert the change? Or create a new character and see if it works there. Looking at the code, I don't see any reason why it shouldn't work, so I'm trying to think of other issues. Also, have you made any other changes to the sheet? Is it possible there's an error in another sheet worker shutting things down? If none of this is the issue, post the HTML for the repeating section, and I'll test the code. PS: you could try changing this line rating += body; to rating = rating + body; but that shouldn't be necessary (just clutching at straws here).
The page I was operating on was a copy of a working version that (while flakey) does what I need and the above issue does not exist. I was really just hoping to understand why that +Body function wasn't working. It's very weird. Anyway, I have a (mostly) working version. Thanks for your help.