Well...my additions will be more like Cantrips than wizardry, but you get the idea. :) Also, because I'm just learning this javascript thing, if there are suggestions to make what I'm sharing here better...please share. I'd love to improve and make these things more efficient. I thought it would be good to add forum similar to the CSS but focus on Sheet Workers capabilities. So, here are things I think should stick around in a fairly obvious place: TheAaronSheet: copy it from this location and paste it at the top of you Sheet Workers Scripts (especially if you're going to use simple sums from repeating sections). Update one field based on the value of another: The HTML: <label class='sheet-Rank-n-XP sheet-nameRankXp'></label>
<input class="sheet-standardNum" type="number" name="attr_xp" title="@{xp}"/>
<select name='attr_rank' title="@{rank}" value='1' class='sheet-rank'>
<option value='1'>Novice</option>
<option value='2'>Seasoned</option>
<option value='3'>Veteran</option>
<option value='4'>Heroic</option>
<option value='5'>Legendary</option>
</select> The Sheet Worker: on("sheet:opened change:xp change:rank", function() {
getAttrs(["xp", "rank"], function(value) {
console.log("xp value: " + value.xp);
console.log("rank value: " + value.rank);
if (value.xp >=80) {
console.log("Setting rank to Legendary");
setAttrs({Rank: 5});
}
else if (value.xp >=60) {
console.log("Setting rank to Heroic");
setAttrs({Rank: 4});
}
else if (value.xp >=40) {
console.log("Setting rank to Veteran");
setAttrs({Rank: 3});
}
else if (value.xp >=20) {
console.log("Setting rank to Seasoned");
setAttrs({Rank: 2});
}
else {
console.log("Setting rank to Novice");
setAttrs({Rank: 1});
}
});
});
Basically, if the Experience Points field meets a particular threshold, then the the Rank drop down box will be updated with the appropriate value. Visual Cues (or changing the background color of field based on criteria): The HTML: <div class="sheet-Strain">
<input type="text" name="attr_strain" title="@{strain}" value="4"
<input type="number" name="attr_StrainMod" title="@{StrainMod}" class="sheet-standardNum" value="0" />
<input class="sheet-standardNum" type="number" name="attr_Strain_max" title="@{Strain_max}" />
<input class="sheet-danger" type="checkbox" name="attr_straindanger" value="1" />
<input class="sheet-critical" type="checkbox" name="attr_straincrit" value="1" />
<input type="number" name="attr_StrainCur" title="@{StrainCur}" class="sheet-derivedStat sheet-strain" readonly />
</div>
The CSS: .charsheet .sheet-danger,
.charsheet .sheet-critical {
display: none;
}
.charsheet input.sheet-danger:checked ~ input.sheet-strain {
background: #e8a400;
}
.charsheet input.sheet-critical:checked ~ input.sheet-strain {
background: #e93a41;
}
The Sheet Worker Code: on("change:strain_max change:totalstrain", function() {
console.log("<====== Checking for Strain Fatigue ======>");
getAttrs(["Strain_max","totalStrain"], function(cvalue) {
console.log("max strain: " + cvalue.Strain_max);
console.log("tot strain: " + cvalue.totalStrain);
var max_Strain = parseInt(cvalue.Strain_max);
var tot_Strain = parseInt(cvalue.totalStrain);
console.log("maxStrain = " + typeof max_Strain);
console.log("totStrain = " + typeof tot_Strain);
strainzone = Math.floor(parseFloat((tot_Strain / max_Strain)) * 100);
console.log("Danger Zone: " + strainzone);
if (strainzone >= 100) {
console.log("At or exceeded Max Strain");
setAttrs({straincrit: 1,
straindanger: 0});
}
else if (strainzone >= 75) {
console.log("Nearing Max Strain");
setAttrs({straincrit: 0,
straindanger: 1});
}
else {
console.log("Nothing to worry about yet");
setAttrs({straincrit: 0,
straindanger: 0});
}
});
});
Here I change the background color the StrainCur field based on the value of that field compared to the max of that field. If the current is less than 75% of the max, then the field remains white; once the current value is 75-99% of the max, the background color the field turns yellow, alerting the player that they are getting to close to their max (and dire consequences if not careful). This change is done by "checking" one of two check boxes and then using the CSS to change the color. If the current value is 100+% of the max, then the color changes red, by "checking" the other checkbox and unchecking the first. So, what else have you all used Sheet Workers for and how'd you accomplish it? :)