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

Sheet Worker problem

Hello, i'm trying to do something apparently simple, but it's not working i want one attribute to contain only text and to be updated based on the vulnerabilities of the character. the player can chose a vulnerability, like this: <select style="margin-left: -30px;" type="select" name='attr_deb' class='dtype2'> <OPTION value="no"></OPTION> <OPTION value="(d)fuoco">🔥</OPTION> <OPTION value="(d)acqua">💧</OPTION> <OPTION value="(d)natura">🌱</OPTION> <OPTION value="(d)ghiaccio">❄️</OPTION> <OPTION value="(d)elettrico">⚡</OPTION> <OPTION value="(d)luce">🌟</OPTION> <OPTION value="(d)oscurità">🌑</OPTION> <OPTION value="(d)impatto">🥊</OPTION> <OPTION value="(d)taglio">🔪</OPTION> <OPTION value="(d)perforante">💥</OPTION> <OPTION value="(d)energia">✨</OPTION> </SELECT> and a resistence and an immunity like this:  <select style="margin-left: -30px;" type="select" name='attr_res' class='dtype2'> <OPTION value="no"></OPTION> <OPTION value="(r)fuoco">🔥</OPTION> <OPTION value="(r)acqua">💧</OPTION> <OPTION value="(r)natura">🌱</OPTION> <OPTION value="(r)ghiaccio">❄️</OPTION> <OPTION value="(r)elettrico">⚡</OPTION> <OPTION value="(r)luce">🌟</OPTION> <OPTION value="(r)oscurità">🌑</OPTION> <OPTION value="(r)impatto">🥊</OPTION> <OPTION value="(r)taglio">🔪</OPTION> <OPTION value="(r)perforante">💥</OPTION> <OPTION value="(r)energia">✨</OPTION> </SELECT>  now i want an attribute called: "debolezze" to be updated with the choises in text format, and the output should look like this: "debolezze": (d)fuoco(r)acqua(i)luce. the sheet worker i tried to use is this: on("change:deb change:res change:imm sheet:opened", function() { getAttrs(["deb","res","imm"], function(values) { let deb = parseInt(values.deb)||0; let res = parseInt(values.res)||0; let imm = parseInt(values.imm)||0; var dri = deb,res,imm; setAttrs({ debolezze: dri }); }); }); but the output stays "0" and not something like (d)fuoco(r)acqua(i)luce. Do any of you have an idea? thank you so much!
1638023181
Finderski
Pro
Sheet Author
Compendium Curator
All your res. Aliens are text strings, so you don’t need the parseInt bit. What’s happening is your parseInt is taking the value and trying to turn the string into an integer, and because it’s not finding a number like string, the or (||) is kicking in and changing it to 0.  Just let deb = values.deb, etc
1638048670

Edited 1638443734
GiGs
Pro
Sheet Author
API Scripter
In addition to Finderski's comment, you need to expressly concatenate (join) those strings: on("change:deb change:res change:imm sheet:opened", function() { getAttrs(["deb","res","imm"], function(values) { let deb = values.deb; let res = values.res; let imm = values.imm; var dri = deb + ", " + res + ", " + imm; setAttrs({ debolezze: dri }); }); }); You can write this line var dri = deb + ", " + res + ", " + imm; in multiple ways. I'd recomment using a template literal, where you enclose the whole thing in backticks (` - these are not apostrophes or quotes). var dri = `${deb}, ${res}, ${imm}`; This allows you to write a string normally (see the commas and spaces), and variables need to be enclosed with ${ }. Once you have used it a couple of times, its much more comfortable than the old string concatenation. My final recommednation isnt about this sheetworker (but would cause it to be rewritten): don't use 3 letter variable names like deb, res, and imm. You aren't limited by length, so use full names - resistance , immunity , etc. It makes your code a lot easier to read and understand (which will be handy when you look at it again a few months later).
Here i am, i finally had the time to test it! and thank you so much to the both of you! now it works great as intended!  as you could imagine i absolutely have no understanding of coding and you helped me a lot! thank you!