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

Sheetworker not recognizing this

1512422703
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
I have a checkbox that indicates whether a person is aiming if checked that character is aiming. It has a value of @{acc}. <input class="sheet-boolean" type="checkbox" name="attr_aim" value="@{acc}" /> My sheetworker is not recognizing the value.  
1512424198
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
I tried to write a sheetworker but it is not working // Checkbox Change Attr on('sheet:opened change:aim', function() { getAttrs(['aim', 'acc' function(values) { setAttrs({aimbonus: math((values.aim)*(values.acc)) }); }); });
1512459436

Edited 1512460642
GiGs
Pro
Sheet Author
API Scripter
You dont terminate the getAttrs statement properly.  Also that Math function doesn't work like that. Try this: on('sheet:opened change:aim', function() { getAttrs(['aim', 'acc'], function(values) { setAttrs({aimbonus: values.aim * values.acc }); }); }); Also, it's a good idea when having issues, to remove the calculation from the setattrs, so you can investigate what's happening. Note: The parseInt function here makes sure you are dealing with a numebr, and the ||0 sets a default of 0, if no number found. <input class="sheet-boolean" type="checkbox" name="attr_aim" value="1" /> on('sheet:opened change:aim', function() { getAttrs(['aim', 'acc'], function(values) { var aim = parseInt(values.aim)||0; var acc = parseInt(values.acc)||0; var result = aim * acc; setAttrs({ aimbonus: result }); }); }); Edit: i dont think you need the value in the checkbox to match acc. In fact, i think that would cause the wrong result. It looks like your calculation is using it as a binary switch, so its value should be 1 or 0.
1512470896
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Thanks, However I punched this in and the result is when the checkbox is checked the aimbonus is 0 and when not checked it reports the acc
1512472496
GiGs
Pro
Sheet Author
API Scripter
I'm a bit too tired (its my bedtime) to try to figure out why that is, but here's a quick fix. In the sheet worker, change the var result line to this: var result = (1-aim) * acc;
1512472770
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
That worked. Thank you.
1512490391
chris b.
Pro
Sheet Author
API Scripter
I think because values.aim will either be undefined or 0, or it will be "@{acc}" ...  so you could do: result = values.aim ? (parseInt(values.acc,10)||0) : 0; but if what you have works already, though im not sure why 1-aim works.
1512501258
Lithl
Pro
Sheet Author
API Scripter
chris b. said: I think because values.aim will either be undefined or 0, or it will be "@{acc}" ...  so you could do: result = values.aim ? (parseInt(values.acc,10)||0) : 0; but if what you have works already, though im not sure why 1-aim works. In G G's code above, aim is defined as  parseInt(values.aim)||0 . 1-aim thus works, but aim is always going to be 0 since values.aim is, as you said, the string "@{acc}".
1512514641
GiGs
Pro
Sheet Author
API Scripter
Ah that explains it. I suggested changing the checkbox value to 1 to avoid weirdness around having it be equal to @{acc}.