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

Two sheetworkers on a single repeater

Hi, I'm hoping to capture two different events in a single repeater. I already have a worker picking up changes in a dropdown (all thanks to GiGs), and that works perfectly now. However I'm hoping to capture changes in a number field, and then apply a second set of values to some of the fields in the repeater (over-writing the values placed in those same fields by the first repeater). What I've tried so far doesn't seem to capture the value change in the number field.on("change:repeating_meleeWeapons:meleeweapontype", function() { //when the WeaponType dropdown changes getAttrs(["repeating_meleeweapons_MeleeWeaponType"], function(values) { //read the value of the selected entry in the WeaponType dropdown const meleeWeapons = { none: {meleeconceal: 0, meleedamaged: 0, meleedamagec: 0, meleedamageb: 0, meleedamagea: 0}, Knife: {meleeconceal: -4, meleedamaged: 0, meleedamagec: 0, meleedamageb: 0, meleedamagea: 0}, Sword_small: {meleeconceal: -1, meleedamaged: 0, meleedamagec: 0, meleedamageb: 0, meleedamagea: 0}, Sword_medium: {meleeconceal: 1, meleedamaged: 0, meleedamagec: 0, meleedamageb: 0, meleedamagea: 0}, Sword_large: {meleeconceal: 3, meleedamaged: 0, meleedamagec: 0, meleedamageb: 0, meleedamagea: 0}, Club: {meleeconceal: 1, meleedamaged: 0, meleedamagec: 0, meleedamageb: 0, meleedamagea: 0}, Staff: {meleeconceal: 5, meleedamaged: 0, meleedamagec: 0, meleedamageb: 0, meleedamagea: 0}, Spear: {meleeconceal: 6, meleedamaged: 0, meleedamagec: 0, meleedamageb: 0, meleedamagea: 0}, Polearm: {meleeconceal: 7, meleedamaged: 0, meleedamagec: 0, meleedamageb: 0, meleedamagea: 0} }; 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_MeleeConceal": thisMeleeWeapon.meleeconceal, "repeating_meleeWeapons_MeleeDamageD": thisMeleeWeapon.meleedamaged, "repeating_meleeWeapons_MeleeDamageC": thisMeleeWeapon.meleedamagec, "repeating_meleeWeapons_MeleeDamageB": thisMeleeWeapon.meleedamageb, "repeating_meleeWeapons_MeleeDamageA": thisMeleeWeapon.meleedamagea }); }); }); on("change:repeating_meleeWeapons:meleeweaponrating", function() { //when the weapon rating changes getAttrs(["repeating_meleeweapons_MeleeWeaponType"], function(values) { //read the value of the selected entry in the WeaponType dropdown const meleeWeapons = { none: {meleeconceal: 0, meleedamaged: 0, meleedamagec: 0, meleedamageb: 0, meleedamagea: 0}, Knife: {meleeconceal: -4, meleedamaged: 1, meleedamagec: 2, meleedamageb: 3, meleedamagea: 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_MeleeConceal": thisMeleeWeapon.meleeconceal, "repeating_meleeWeapons_MeleeDamageD": thisMeleeWeapon.meleedamaged, "repeating_meleeWeapons_MeleeDamageC": thisMeleeWeapon.meleedamagec, "repeating_meleeWeapons_MeleeDamageB": thisMeleeWeapon.meleedamageb, "repeating_meleeWeapons_MeleeDamageA": thisMeleeWeapon.meleedamagea }); }); }); So the idea is that selecting the weapon gives you zero values, then defining your skill rating gives you actual values (which need to be calculated from that skill rating... another challenge) What I'm hoping to do here is something like this- Knife: {meleeconceal: -4, meleedamaged: (@{MeleeWeaponRating} * 0.25), meleedamagec: (@{MeleeWeaponRating} * 0.5), meleedamageb: (@{MeleeWeaponRating} * 0.75), meleedamagea: (@{MeleeWeaponRating})} Does that make sense?
1586861353
GiGs
Pro
Sheet Author
API Scripter
In both of thiose workers the destination  attributes are the same. You very rarely want different workers affecting the same attribute. There are cases where you might do this, but it's extremely rare - this isnt one of them.  When you have multiple attributes contributing to the same final attributes, you do it in just one sheet worker. Why are the stats of the knife different in the two workers? I'm not following exactly what you want to do within the worker, but to grab multiple attributes for use in a worker, you just chain them together like so on("change:repeating_meleeWeapons:meleeweaponrating change:repeating_meleeWeapons:meleeweapontype", function() { getAttrs(["repeating_meleeweapons_MeleeWeaponType, repeating_meleeweapons_MeleeWeaponType"], function(values) { Notice the syntax is slightly different for the two rows.
What I was thinking was when a player chooses a weapon, they get the stats that relate to that weapon and don't change . There are other stats though- damage is connected to the Rating of the skill used to wield the weapon. So if you have a 3, you're going to less damage than someone with a 7. So... I was thinking that the moment you select a weapon, the damage values fill with zeros. Then when you adjust the Rating, the damage values fill in based on the number. This number changes as you skill up, and so will those damage values. Would it work if the first sheetworker only filled in the non-changing numbers, leaving the rest blank? Then the second sheetworker only operated on those previously blank ones... no crossover. Finally, there's the math... I'm hoping that the sheetworker's values database thingy can have math in it that works off the Rating, on an on("change...") basis. Is that possible? I outlined what the math would look like in my first post in this thread.
1586864409
GiGs
Pro
Sheet Author
API Scripter
Tuck S. said: Would it work if the first sheetworker only filled in the non-changing numbers, leaving the rest blank? Then the second sheetworker only operated on those previously blank ones... no crossover. Yes you can do that. That's the normal way in fact. Finally, there's the math... I'm hoping that the sheetworker's values database thingy can have math in it that works off the Rating, on an on("change...") basis. Is that possible? I outlined what the math would look like in my first post in this thread. Yes, you can do math. You don't use attribute names in this form though @{attribute} as sheet workers dont know anything about what's on the sheet except the values you supply them in the getAttrs line. So you might have, for example 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; This let rating line gets the value and converts it to a number. By default, attributes in roll20 are stored as strings (text), and you need to convert, say "3" to 3, before you can perform math with it. Then you can do         let damage = rating * 0.75; So arithemtic is easy. That said, you probably want to round to a whole number, so that would be         let damage = Math.round(rating * 0.75);
I got it working, thanks for all the help. However I do have a more general question about sheet workers. Right now it seems that the on change event happens when one clicks away from the thing one is changing. Like if I change the value in a number field, the worker doesn't notice till I click off the field somewhere else on the page. Is there a way to get the worker to notice each time the value in the field is updated at all? So it updates the results as one updates the value...? I get that this would slow things down in some circumstances, but this is a very small set of numbers and math. I'm pretty sure it would not be noticable.
1586904779
GiGs
Pro
Sheet Author
API Scripter
No, thats a limitation of html and change:events  on roll20 - it doesnt register a change until you click away, so there's no way to get it to notice an update without doing that.
Good to know, thanks.