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 .
Advertisement Create a free account Compendium in Game, Join Today

Trouble setting Evasion on my Sheet

1613890484

Edited 1613890697
So, I am building my first character sheet and I am running into some trouble. I am running a personal system and I wish to set the characters Evasion to be equal to the Dexterity (which is manually input by the user) times 5, but I am not gettin back any value. Code: < div   class = "stat-block flex-center" >        < label > Destreza </ label >        < input   name = "attr_destreza"   type = "number"   value = "" >        < span   name = "attr_destreza" ></ span >        < button   name = "roll_destreza"   type = "roll"   value = "&{template:default} {{name=destreza}} {{Result=[[(@{destreza}d10)]]}}" ></ button >      </ div > < div   class = "stat-block flex-center" >    < label > Evasión </ label >    < input   type = "hidden"   name = "attr_evasion"   value = "0"   />    < input   type = "number"   name = "attr_evasion"   value = "@{evasion}"   disabled = "true" /> </ div > < script   type = "text/worker" >     const stats = ["fuerza", "destreza", "constitucion", "entendimiento", "fe", "bravura", "carisma",];     stats.forEach(stat => {         on(`change:${stat}`, ()                 });             });         });     }); on("sheet:opened change:destreza", function() {   getAttrs(["DESTREZA"], function(values) {      setAttrs({          evasion: Math.floor(values.destreza * 5)      });   }); }); </ script >
1613920017
Andreas J.
Forum Champion
Sheet Author
Translator
It might not due to not having forced the attribute vale to be a number. See these examples: <a href="https://wiki.roll20.net/Sheet_Worker_Snippets" rel="nofollow">https://wiki.roll20.net/Sheet_Worker_Snippets</a>
1613945627
I am sorry but I can't seem to get it right. I don't know if this is what I am supposed to do, I am pretty new to html and javascritp. This is what I try: on("sheet:opened&nbsp;change:destreza",&nbsp;function()&nbsp;{ &nbsp;&nbsp;getAttrs(["destreza"],&nbsp;function(values)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;destreza&nbsp;=&nbsp;parseInt(values["destreza"])||0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;output&nbsp;=&nbsp;destreza&nbsp;*5 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setAttrs({ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"evasion":&nbsp;output &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;}); }); Or is the "Destreza" attribute field the one that I should be modifying?
1613948555

Edited 1613948594
∇ince
Pro
Sheet Author
I think you only want to use one input for evasion. Let your sheetworker do the calculation for evasion and use an "attribute named span" to show evasion's current value.&nbsp; Like you did with destreza. &lt;div class="stat-block flex-center"&gt; &lt;label&gt;Evasión&lt;/label&gt; &lt;input type="hidden" name="attr_evasion" value="0"/&gt; &lt;span name="attr_evasion"&gt;&lt;/span&gt; &lt;/div&gt; Your sheetworker looks OK, but I'm probably not the best to give js advice... ;-(&nbsp; That said, I might suggest adding some logs in your sheetworkers(at least temporarily) to help see what is happening within your worker at various points. ie console.log("destreza :"+destreza);
1613954120
Ok I tried what you said but I still don't get the correct value return, It now says "1"&nbsp; instead. I have no idea what I am doing wrong, I tried reading different sheets and copying what they do but I can't seem to get the same result. WORKSHEET on("sheet:opened&nbsp;change:destreza",&nbsp;function()&nbsp;{ &nbsp;&nbsp;getAttrs(["destreza"],&nbsp;function(values)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;output&nbsp;=&nbsp;parseInt(values["destreza"])||0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setAttrs({ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"evasion":&nbsp;output &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;}); }); HTML &lt; div &nbsp; class = "stat-block&nbsp;flex-center" &gt; &nbsp;&nbsp; &lt; label &gt; Evasión &lt;/ label &gt; &nbsp;&nbsp; &lt; input &nbsp; type = "hidden" &nbsp; name = "attr_evasion" &nbsp; value = "0" /&gt; &nbsp;&nbsp; &lt; span &nbsp; name = "attr_evasion" &gt;&lt;/ span &gt; &lt;/ div &gt;
1613965648

Edited 1613965964
∇ince
Pro
Sheet Author
This is working for me in a quick test... (I removed some of the extra html just to "cut to the quick") Maybe this will help. destreza: &lt;input type="number" name="attr_destreza" value="0"/&gt; &lt;br&gt; evasion: &lt;input type="hidden" name="attr_evasion" value="0"/&gt; &lt;span name="attr_evasion"&gt;&lt;/span&gt; &lt;script type="text/worker"&gt; on("sheet:opened change:destreza", function() { getAttrs(["destreza"], function(values) { var output = Math.floor((parseInt(values["destreza"])||0)*5); setAttrs({ "evasion": output }); }); }); &lt;/script&gt;
1613966803

Edited 1613966836
Ok, I copy what you did in a new custom Sheet and it worked but when I tried to reproduce the same result in my original sheet I keep failing to get a number. And I honestly don't know the reason, I'll copy the entire code so if anyone can see what's wrong they can tell what it is so I don't keep making the same mistake. &lt;!-- all sheet code here --&gt; &lt;/div&gt; &lt;div&gt; &lt;button type="action" name="act_character" &gt;Character&lt;/button&gt; &lt;button type="action" name="act_journal" &gt;Journal&lt;/button&gt; &lt;button type="action" name="act_configuration" &gt;Configuration&lt;/button&gt; &lt;/div&gt; &lt;input type='hidden' class='sheet-tabstoggle' name='attr_sheetTab' value='character' /&gt; &lt;div class='sheet-character'&gt; &lt;h2&gt;Character&lt;/h2&gt; &lt;span&gt;character Stuff Goes here &lt;/span&gt; &lt;/div&gt; &lt;div class='sheet-journal'&gt; &lt;h2&gt;Journal/Notes&lt;/h2&gt; &lt;span&gt;Journal/Notes Stuff Goes here&lt;/span&gt; &lt;/div&gt; &lt;div class='sheet-config'&gt; &lt;h2&gt;Config/Settings&lt;/h2&gt; &lt;span&gt;Sheet Config/Settings goes here&lt;/span&gt; &lt;/div&gt; &lt;!--Hoja de Personaje--&gt; &lt;div class="container"&gt; &lt;div class="col"&gt; &lt;div class="col"&gt;&lt;label&gt;Nombre&lt;/label&gt;&lt;input type="text" name="attr_character_name"/&gt;&lt;/div&gt; &lt;div class="col"&gt;&lt;label&gt;Raza&lt;/label&gt;&lt;select id="raza1" onchange="razap(this);"&gt; &lt;option value="Humano"&gt;Humano&lt;/option&gt; &lt;option value="Elfo"&gt;Elfo&lt;/option&gt; &lt;/select&gt;&lt;/div&gt; &lt;div class="col"&gt;&lt;label&gt;Raza Agregada&lt;/label&gt;&lt;select id="raza2" onchange="razap2(this);"&gt; &lt;option value="Humano"&gt;Humano&lt;/option&gt; &lt;option value="Elfo"&gt;Elfo&lt;/option&gt; &lt;/select&gt;&lt;/div&gt; &lt;div class="col"&gt; &lt;div class="col"&gt;&lt;label&gt;Altura&lt;/label&gt;&lt;input type="option" name="attr_character_name" /&gt;&lt;/div&gt; &lt;div class="col"&gt;&lt;label&gt;Peso&lt;/label&gt;&lt;input type="text" name="attr_raza1" /&gt;&lt;/div&gt; &lt;div class="col"&gt;&lt;label&gt;Sexo&lt;/label&gt;&lt;input type="text" name="attr_raza2" /&gt;&lt;/div&gt; &lt;div class="col"&gt;&lt;label&gt;Ojos&lt;/label&gt;&lt;input type="text" name="attr_raza2" /&gt;&lt;/div&gt; &lt;div class="col"&gt;&lt;label&gt;Cabellos&lt;/label&gt;&lt;input type="text" name="attr_raza2" /&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div class="col"&gt;&lt;label&gt;EXP:&lt;/label&gt;&lt;input type="number" name="attr_xp" /&gt;&lt;/div&gt; &lt;div class="col"&gt;&lt;label&gt;PH:&lt;/label&gt;&lt;input type="number" name="attr_ph" /&gt;&lt;/div&gt; &lt;/div&gt; &lt;H1&gt;Estadisticas&lt;/H1&gt; &lt;div class="stats section"&gt; &lt;div class="stat-block flex-center"&gt; &lt;label&gt;Fuerza&lt;/label&gt; &lt;input name="attr_fuerza" type="number" value=""&gt; &lt;span name="attr_fuerza"&gt;&lt;/span&gt; &lt;button name="roll_fuerza" type="roll" value="&amp;{template:default} {{name=fuerza}} {{Result=[[(@{fuerza}d10)]]}}"&gt;&lt;/button&gt; &lt;/div&gt; &lt;div class="stat-block flex-center"&gt; &lt;label&gt;Destreza&lt;/label&gt; &lt;input name="attr_destreza" type="number" value="0"&gt; &lt;span name="attr_destreza"&gt;&lt;/span&gt; &lt;button name="roll_destreza" type="roll" value="&amp;{template:default} {{name=destreza}} {{Result=[[(@{destreza}d10)]]}}"&gt;&lt;/button&gt; &lt;/div&gt; &lt;div class="stat-block flex-center"&gt; &lt;label&gt;Constitución&lt;/label&gt; &lt;input name="attr_constitucion" type="number" value=""&gt; &lt;span name="attr_constitucion"&gt;&lt;/span&gt; &lt;button name="roll_constitucion" type="roll" value="&amp;{template:default} {{name=constitucion}} {{Result=[[(@{constitucion}d10)]]}}"&gt;&lt;/button&gt; &lt;/div&gt; &lt;div class="stat-block flex-center"&gt; &lt;label&gt;Entendimiento&lt;/label&gt; &lt;input name="attr_entendimiento" type="number" value=""&gt; &lt;span name="attr_entendimiento"&gt;&lt;/span&gt; &lt;button name="roll_entendimiento" type="roll" value="&amp;{template:default} {{name=entendimiento}} {{Result=[[(@{entendimiento}d10)]]}}"&gt;&lt;/button&gt; &lt;/div&gt; &lt;div class="stat-block flex-center"&gt; &lt;label&gt;Fe&lt;/label&gt; &lt;input name="attr_fe" type="number" value=""&gt; &lt;span name="attr_fe"&gt;&lt;/span&gt; &lt;button name="roll_fe" type="roll" value="&amp;{template:default} {{name=fe}} {{Result=[[(@{fe}d10)]]}}"&gt;&lt;/button&gt; &lt;/div&gt; &lt;div class="stat-block flex-center"&gt; &lt;label&gt;Bravura&lt;/label&gt; &lt;input name="attr_bravura" type="number" value=""&gt; &lt;span name="attr_bravura"&gt;&lt;/span&gt; &lt;button name="roll_bravura" type="roll" value="&amp;{template:default} {{name=bravura}} {{Result=[[(@{bravura}d10)]]}}"&gt;&lt;/button&gt; &lt;/div&gt; &lt;div class="stat-block flex-center"&gt; &lt;label&gt;Carisma&lt;/label&gt; &lt;input name="attr_carisma" type="number" value=""&gt; &lt;span name="attr_carisma"&gt;&lt;/span&gt; &lt;button name="roll_carisma" type="roll" value="&amp;{template:default} {{name=carisma}} {{Result=[[(@{carisma}d10)]]}}"&gt;&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="abilities section"&gt; &lt;div class="stat-block flex-center"&gt; &lt;label&gt;Academisismo&lt;/label&gt; &lt;input name="attr_academisismo" type="number" value=""&gt; &lt;span name="attr_academisismo"&gt;&lt;/span&gt; &lt;button name="roll_academisismo" type="roll" value="&amp;{template:default} {{name=academisismo}} {{Result=[[(@{academisismo}+@{entendimiento})d10k@{academisismo}!!]]}}"&gt;&lt;/button&gt; &lt;/div&gt; &lt;div class="stat-block flex-center"&gt; &lt;label&gt;Alerta&lt;/label&gt; &lt;input name="attr_alerta" type="number" value=""&gt; &lt;span name="attr_alerta"&gt;&lt;/span&gt; &lt;button name="roll_alerta" type="roll" value="&amp;{template:default} {{name=alerta}} {{Result=[[(@{alerta}+?{Name of Query|entendimiento, @{entendimiento}|destreza, @{destreza}})d10k@{alerta}!!]]}}"&gt;&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; evasion: &lt;input type="hidden" name="attr_evasion" value="0"/&gt; &lt;span name="attr_evasion"&gt;&lt;/span&gt; &lt;div class="stat-block flex-center"&gt; &lt;label&gt;DEfeNSE&lt;/label&gt; &lt;input name="attr_defense" type="value"&gt; &lt;input name="attr_defense" type="value"&gt; &lt;/div&gt; &lt;div class="stat-block flex-center"&gt; &lt;label&gt;HIT POINTS&lt;/label&gt; &lt;input name="attr_hit_points" type="number" value=""&gt; &lt;input name="attr_hit_points_max" type="number" value=""&gt; &lt;/div&gt; &lt;/div&gt; &lt;!-- ---------------------------SHEET WORKERS----------------- --&gt; &lt;script type="text/worker"&gt; &lt;h1&gt;Valor en Estadistica&lt;/h1&gt; const stats = ["fuerza", "destreza", "constitucion", "entendimiento", "fe", "bravura", "carisma",]; stats.forEach(stat =&gt; { on(`change:${stat}`, () }); }); }); }); &lt;h1&gt;Tirada de Habilidad&lt;/h1&gt; const habilidad = ["alerta","academisismo"]; stats.forEach(stat =&gt; { on(`change:${stat}`, () }); }); }); }); &lt;h1&gt;evasion&lt;/h1&gt; on("sheet:opened change:destreza", function() { getAttrs(["destreza"], function(values) { var output = Math.floor((parseInt(values["destreza"])||0)*5); setAttrs({ "evasion": output }); }); }); &lt;h1&gt;Tabs&lt;/h1&gt; const buttonlist = ["character","journal","configuration"]; buttonlist.forEach(button =&gt; { on(`clicked:${button}`, function() { setAttrs({ sheetTab: button }); }); }); &lt;/script&gt;
1613967617

Edited 1613969106
∇ince
Pro
Sheet Author
There are some header tags(HTML) inside your sheetworkers that need to be removed.&nbsp; Just noticed that would be an immediate issue. ;-)&nbsp; If you want a single line comment within the js, use "//" ie //evasion //tabs //foo ... etc.
1613969954
Ahh thank you for that!! They are already removed! ∇ince said: There are some header tags(HTML) inside your sheetworkers that need to be removed.&nbsp; Just noticed that would be an immediate issue. ;-)&nbsp; If you want a single line comment within the js, use "//" ie //evasion //tabs //foo ... etc.
1614029256
The only "solution" I have found so far is to do something like this in the HTML rather than using the Javascript Worker: &nbsp;&nbsp; &lt; input &nbsp; type = "text" &nbsp; name = "attr_eva" &nbsp; value = (@{destreza}*5) &nbsp; disabled = "false" &nbsp; /&gt;
1614052845

Edited 1614053099
∇ince
Pro
Sheet Author
MaRiTg R. said: The only "solution" I have found so far is to do something like this in the HTML rather than using the Javascript Worker: &nbsp;&nbsp; &lt; input &nbsp; type = "text" &nbsp; name = "attr_eva" &nbsp; value = (@{destreza}*5) &nbsp; disabled = "false" &nbsp; /&gt; That's the way sheets handled attribute calculations before sheetworkers were allowed.&nbsp; It still works and there are many older sheets that haven't been converted to using sheetworkers.&nbsp; Be warned; you might experience strange behavior in calculations when you mix html calcs and sheetworker calcs.&nbsp; I would recommend breaking your sheetworker down(don't be afraid to use console logs to spam your steps, just remove the superfluous ones later.) Get it working as expected for a small sub-set of sheet attributes then add to it. That way it's easier to identify where the problem lies.&nbsp; I'm more of a sheetworker observer/thief since I mainly steal other's code to make it fit my needs, but rarely write my own since I don't want to give GiGs too many heart attacks. ;-P&nbsp; Hopefully you can get some better advice from some of the more experienced scriptomancers.
1614113632
Andreas J.
Forum Champion
Sheet Author
Translator
More info and comments regarding auto-calc can be found here, probably overlaps somewhat with what Vince just said: <a href="https://wiki.roll20.net/Auto-Calc" rel="nofollow">https://wiki.roll20.net/Auto-Calc</a>
1614122808
Ok, after removing and changing staff I think I pinpoint the problem. It's this: /est const stats = ["fuerza", "destreza", "constitucion", "entendimiento", "fe", "bravura", "carisma",]; stats.forEach(stat =&gt; { on(`change:${stat}`, () }); }); }); }); //hab const habilidad = ["alerta","academisismo"]; stats.forEach(stat =&gt; { on(`change:${stat}`, () }); }); }); }); If I remove that, the code works perfectly, I don't really undestand why but it works. If anyone has any idea why feel free to tell me, but I think that with that the problem is solved! Thank you so much Andreas and specially Vince for the help!