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

[Sheet Workers] The Basics

1456699276

Edited 1456700863
Coal Powered Puppet
Pro
Sheet Author
How do I make sheet worker to replace an disabled field? Here is an auto calc field: <input type="number" class="sheet-stats-base" name="attr_willpower" value="0" readonly /> I thought the sheet worker code was suppose to look like this:     on("change:physique change:intellect change:willpower_mod change:npc_willpower", function() {         getAttrs(["physique", "intellect", "willpower_mod", "npc_willpower"], function(values) {             setAttrs({                 willpower: parseInt(values.physique) + parseInt(values.intellect) + parseInt(values.willpower_mod) + parseInt(values.npc_willpower)             });         });     }); But It appears not to be the case.   Edit: Jake M. is very much right, but I posted the wrong code for my question.  So, the above is now the code I currently have.  Still doesn't work.
change the field to read only.  IIRC disabled can't be altered by sheet workers
Corrected the orginal post; Jake M. pointed out where I made a mistake.  Still doesn't work
1456701187
vÍnce
Pro
Sheet Author
Does this work? on("change:physique change:intellect change:willpower_mod change:npc_willpower", function() {         getAttrs(["physique", "intellect", "willpower_mod", "npc_willpower"], function(values) {             setAttrs({                 willpower: (values.physique + values.intellect + values.willpower_mod + values.npc_willpower)             });         });     });
I am getting every number in a line.  If the math is suppose to be "7+0+3+0+0", the number that shows up is "70300".  How can I make this add up?
1456703835
vÍnce
Pro
Sheet Author
    on("change:physique change:intellect change:willpower_mod change:npc_willpower", function() {         getAttrs(["physique", "intellect", "willpower_mod", "npc_willpower"], function(values) {             setAttrs({                 willpower: (+values.physique + +values.intellect + +values.willpower_mod + +values.npc_willpower)             });         });     });
1456703960
vÍnce
Pro
Sheet Author
Sorry, I'm just a guy with a set of hammers...  ;-)
You think you got some hammers?  You haven't looked in my tool box. And when I run out of hammers, I can headbutt those nails into the board.  
1456704185
vÍnce
Pro
Sheet Author
LOL
The "+" signs made the whole things stop working.  Do I need a bigger hammer?
1456704475
vÍnce
Pro
Sheet Author
This worked for me on a sheet I was working on... on('change:pp change:gp change:ep change:sp change:cp change:armor_weight change:armor_cost', function(){ getAttrs(['pp','gp','ep','sp','cp','armor_weight','armor_cost'], function(values){ setAttrs({ total_coin_weight: (+values.pp + +values.gp + +values.ep + +values.sp + +values.cp), total_armor_weight: (+values.armor_weight), total_armor_cost: Number(+values.armor_cost).toFixed(2) }); }); });
1456706954
vÍnce
Pro
Sheet Author
This is bothering me... how about this? on("change:physique change:intellect change:willpower_mod change:npc_willpower", function() {         getAttrs(["physique", "intellect", "willpower_mod", "npc_willpower"], function(values) {             setAttrs({                 willpower: (parseInt(values.physique) + parseInt(values.intellect) + parseInt(values.willpower_mod) + parseInt(values.npc_willpower))             });         });     });
I reworked it and it is awesome.  Thank a million, Vince.  You are all that and box of burbon.  
1456708105
vÍnce
Pro
Sheet Author
Ting. Ting. Ting.  Lol
For the record, I removed the "parseInt".  Decimals matter not here.  
1456709498
vÍnce
Pro
Sheet Author
"We don't  need no stinking decimals..."
So, if I were to want a sheet worker to apply a number to multipe places,it would look like this: setAttrs({ Vitality_1: (values.foo), Vitality_2: (values.foo), Vitality_3: (values.foo) Right?
1457369381
vÍnce
Pro
Sheet Author
That looks about right.  But I'm totally unqualified to make that statement.  lol But, now you have me thinking of how I can trigger multiple attributes based off of one.  hmmmm
That's how you do, I am guessing.  Because it worked.