
I have been digging for a while on this one. I can not find an issue with my sheet worker script. I used one from Kryx that i found on the fourm and adjusted it to fit what i needed. I am sure it is some small issue but after 2 hours I can not find it.
I what to click a button that will then run the script to reduce armor by 1 if the max armor is above 0. if it is 0 then i want it to check the next armor and repeat. It is for a home brew rule set for armor in cyberpunk that we use.
Here is the button:
<button type="action" name="act_hit" class="txt-btn">HIT</button>
This is the armor in the sheet:
<h3>ARMOR:</h3>
<input type="checkbox" name="attr_ar1e" value="1"/>
ARMOR: <input name="attr_a1" type="text" style="width: 150px;"/>
TYPE: <input name="attr_a1type" type="text" style="width: 50px;" value="UNDER"/><br/>
RATING: <input type="number" name="attr_ar1" value="0" /> / <input type="number" name="attr_ar1_max" value="0"/>
ENCUMBRANCE: <input type="number" name="attr_a1enc" value="0" />
<hr>
<input type="checkbox" name="attr_ar2e" value="1"/>
ARMOR: <input name="attr_a2" type="text" style="width: 150px;" />
TYPE: <input name="attr_a2type" type="text" style="width: 50px;" value="ARMOR"/><br/>
RATING: <input type="number" name="attr_ar2" value="0" /> / <input type="number" name="attr_ar2_max" value="0"/>
ENCUMBRANCE: <input type="number" name="attr_a2enc" value="0" />
<hr>
<input type="checkbox" name="attr_ar3e" value="1"/>
ARMOR: <input name="attr_a3" type="text" style="width: 150px;" />
TYPE: <input name="attr_a3type" type="text" style="width: 50px;" value="SHEILD"/><br/>
RATING: <input type="number" name="attr_ar3" value="0" /> / <input type="number" name="attr_ar3_max" value="0"/>
ENCUMBRANCE: <input type="number" name="attr_a3enc" value="0" />
This is the sheet worker:
<script type="text/worker">
on("clicked:hit", function(){
getAttrs(["ar1_max", "ar2_max", "ar3_max"], function(values){
var ar1_max = parseInt(values.ar1_max);
var ar2_max = parseInt(values.ar2_max);
var ar3_max = parseInt(values.ar3_max);
if (ar3_max > 0) {
setAttrs({"ar3_max": (ar3_max - 1) });
} else if {(ar2_max > 0) {
setAttrs({"ar2_max": (ar2_max - 1) });
} else if {(ar1_max > 0) {
setAttrs({"ar1_max": (ar1_max - 1) });
}
});
});
Any help would be great. I am just stuck.
Thank you,