Hi again, I managed to get the sheetworker script working, but it's returning an incorrect value. Here is my code (the pertinent parts at least):
<h1>Caractéristiques</h1>
<span>FOR - Force </span> <INPUT type="number" name="attr_force" value="0"></INPUT><br>
<span>CON - Constitution </span> <INPUT type="number" name="attr_const" value="0"></INPUT><br>
<span>DEX - Dextérité </span> <INPUT type="number" name="attr_dext" value="0"></INPUT><br>
<span>INT - Intelligence </span> <INPUT type="number" name="attr_intel" value="0"></INPUT><br>
<span>SAG - Sagesse </span> <INPUT type="number" name="attr_sage" value="0"></INPUT><br>
<span>CHA - Charisme </span> <INPUT type="number" name="attr_chari" value="0"></INPUT><br>
<h1>Compétences</h1>
<span> Caracs - Rang - Total</span> <!-- This is a label above the 3 columns of numbers next to the skill name -->
<span>Acrobatie (FOR, DEX) </span>
<input type="number" name="attr_acrocarac" value="(@{force}+@{dext})" disabled="true" /> <!-- this displays correctly -->
<input type="number" name="attr_acrorang" value="0" />
<input type="number" name="attr_acrobatie" readonly >
<script type="text/worker">
on('ready change:acrocarac change:acrorang', function() {
getAttrs(['acrocarac', 'acrorang'], function(values) {
var acrocarac = parseInt(values.acrocarac) || 0,
acrorang = parseInt(values.acrorang) || 0;
setAttrs({ acrobatie: acrorang === 0 ? 0 : acrocarac + acrorang });
});
});
</script>
(...)
<span>Athlétisme (FOR, CON) </span>
<input type="number" name="attr_athletismecarac" value="(@{force}+@{const})" disabled="true" />
<input type="number" name="attr_athletismerang" value="0" />
<input type="number" name="attr_athletisme" value="(@{athletismecarac}+@{athletismerang})" disabled="true" />
<br>
The sheetworker should return the sum of acrocarac and acrorang, unless acrorang=0, in which case the total is always 0. The sheetworker returns only the value of acrorang, without adding acrocarac to it (so I don't even know if the condition (acrorang===0) is being tested. Possibly it somehow sets the value of acrorand to 0 for some reason. In the code above I included another skill, to show how it should work. This is without the sheetworker and it works correctly, albeit without the condition (acrorang===0...). I thought that the problem could be the result of one of the values being somehow a string, but that doesn't seem to be the case. This is what I like about coding, it's a lot of detective work ;) Also, I don't fully understand this: "parseInt(values.acrocarac) || 0" parseInt changes even a string into a number, so it's there to make sure the variable is a number, ok. Can you tell me what "|| 0" is and does please? I can't seem to find a reference for it. Thanks!