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

I need help concerning my custom sheet sheetworker

512x245 (Original: 512x245) 512x245 (Original: 512x245) Hello, I'm trying to create my own custom charactersheet and I am completely new to coding, I'm trying to learn basics since last week. I would like to have some help on a formula. I can't make this work somehow, my "racemod" seem to always be 0 or 5 depending on if I put the "totfor" addition before or after the "if". Changing racefor (and consequently racemod) on the sheet doesn't affect "totfor" and I don't understand what is wrong here, since the "lvlfor" part works perfectly. Any idea ? Sorry for my english, and thank you for reading my post.
1701280900

Edited 1701280980
GiGs
Pro
Sheet Author
API Scripter
Never post screenshots of code, always post the actual code. Also, this page might help: <a href="https://cybersphere.me/roll20-sheet-author-master-list/" rel="nofollow">https://cybersphere.me/roll20-sheet-author-master-list/</a> You want to remove change:basefor - thats an attribute being created by the worker, having it in the event line where you watch&nbsp; for changes might create an infinite loop. The big problem is your if statement, which I cant copy because its a screenshot. But you want to change that = to == or ===. In javascript, an = is read as an assignment. When comparing values, you need to use double or triple equals.
Thank you for your answer, i thought a screenshot would make it easier to read but i get why i shouldn't now. I applied your advices and it now works perfectly fine Thank you very much !
Hello again, I used the sheet autor master list blog today, and progressed a lot on my work thanks to that. But if you are still there, I have two new questions, and i didnt found any answer on this blog nor on other websites. 1 - What command should i use in my html if i want a result to appear without using "input" ? I just need raw results from my sheetworker, without the input box. I tried "output" but it doesn't seem to work. 2- Is there any way to fix input number boxes on various width on my css ? I'm using : } .ui-dialog .charsheet input[type=number]{ width: 5em ; }&nbsp; But I don't know if and how i can change it depending on divs, i didn't found any answer either. Thank you for reading me.
1701379020
GiGs
Pro
Sheet Author
API Scripter
For the first question, I think you are asking if you can show text but have it not be editable? The most common way to do this is using a span , like so &lt;span&gt;Some text&lt;/span&gt; You can also use headings (h1-h6), paragraphs (p), even divs. You could also use an input and make it readonly or disabled. Then it looks like an input but the user wont be able to change it. &lt;input type="text" name="attr_example" vale="whatever I want to display" readonly&gt; Do any of these answer your question? For styling (which include width), you are best off using CSS as you illustrate above. But inputs specifically require you include more class entries - there is some default styling assigned by roll20, often to the width, and you need a lot of specificity (extra classes) to override it. I always put everything inside a big div, with class of container, so I can do this: &lt;div class="container"&gt; &lt;!-- this is at the very top of the sheet - everything goes inside this div --&gt; &lt;input type="text" name="attr_example" vale="whatever I want to display" class="some-class"&gt; &lt;/div&gt; &lt;!-- that top div needs a closure -&gt; and then address it with CSS like so: .ui-dialog .charsheet .container input[type="number"].some-class { width: 5em ; } You usually don't need everything there, but you have the option of being as specific as you want and getting everything.
1701383296

Edited 1701383361
vÍnce
Pro
Sheet Author
Just to add; this comes from the wiki and might help with just displaying output to the sheet; You can also use a &lt;span&gt; -element to display a read-only attribute on your sheet, e.g. &lt; span name="attr_strength_mod"&gt;&lt;/ span&gt; . It is possible to use a &lt;span&gt; -element to show the same value as an exiting attribute &lt;input&gt; -element with the same name. Updating the value in the &lt;input&gt; -element will update the displayed value of the &lt;span&gt; -element. (For a &lt;span&gt; -attribute to show properly, it needs to be saved on the sheet in some form, either with a normal input or a &lt;input type="hidden"&gt;
Thank you for your answers guys, I'm using now &lt;span&gt; to display my numbers and it works fine, thank you @vÌnce And i struggled a lot to use your CSS method @GiGs, it didn't work at first and i didnt understand why, but then I deleted all those parts and wrote it again, I don't know how but it fixed it, and now I get what i want, thank you for that ! You guys are so precise and help so fast that's awesome
1701451796
GiGs
Pro
Sheet Author
API Scripter
I'm glad you got there in the end :)
Hello again, I worked a lot on my custom sheet this week but i think i came to a difficulty i can't pass without help. Thing is pretty simple, i calculated the sum of a repeating section using this : on('change:repeating_defenses', () =&gt; { &nbsp; getSectionIDs('repeating_defenses', ids =&gt; { &nbsp; &nbsp; const armure_score = []; &nbsp; &nbsp; ids.forEach(id =&gt; armure_score.push(`repeating_defenses_${id}_armorscore`)); &nbsp; &nbsp; getAttrs(armure_score, values =&gt; { &nbsp; &nbsp; &nbsp; &nbsp;let totarmure = 0; &nbsp; &nbsp; &nbsp; &nbsp;armure_score.forEach(row =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const armorscore = +values[row] || 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; totarmure += armorscore; &nbsp; &nbsp; &nbsp; &nbsp;});&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setAttrs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; totarmure:totarmure &nbsp; &nbsp; &nbsp; &nbsp;}); &nbsp; &nbsp; }); &nbsp; }); }); And it works perfectly fine, but here is my problem : i want to use this result and combine it to other attributes, but somehow it does'nt work. I tried this for example, but none on the values are displayed on my charactersheet: on("change:totarmure change:basedef sheet:opened", function() &nbsp;{ &nbsp;getAttrs(["totarmure", "basedef", "totref", "totaldef", "surpridef"], function(values) &nbsp;{ &nbsp;let totref = +values.totref||0; &nbsp;let totarmure= +values.totarmure||0; &nbsp;let totaldef; &nbsp;let basedef; &nbsp;let surpridef; &nbsp;let basedef = totref+50; &nbsp;let totaldef= basedef+totarmure; &nbsp;let surpridef= totarmure+50; &nbsp; &nbsp;setAttrs({ basedef:basedef, totaldef:totaldef, surpridef:surpridef &nbsp; }); &nbsp; }); &nbsp; }); So i tried to figure it out and i think the answer might be there&nbsp; <a href="https://cybersphere.me/repeating-sections-and-global-stats/" rel="nofollow">https://cybersphere.me/repeating-sections-and-global-stats/</a> &nbsp;but this is way to complex for me and the example showed there isn't really close to what i am trying to get. Any idea ?&nbsp; Thank you for reading me !
1701886970

Edited 1701887207
vÍnce
Pro
Sheet Author
See if replacing the applicable lines above with these helps; const totref = +values.totref || 0; const totarmure = +values.totarmure || 0; let totaldef = +values.totaldef || 0; let basedef = +values.basedef || 0; let surpridef = +values.surpridef || 0; basedef = totref + 50; totaldef = basedef + totarmure; surpridef = totarmure + 50; I often use console.log() through various stages of the code when testing to help see what is happening or not happening...&nbsp; Also, Make sure that your inputs are not set to "disabled".&nbsp; I believe that can cause problems with sheetworkers updating them.&nbsp; One option is to use "readonly" if you only want to display the output.
1701889926

Edited 1701910303
GiGs
Pro
Sheet Author
API Scripter
Yoiur second example is just for global stats, no repeating section included? As Vince points out, it seems like you havent grabbed the values form the sheet. You have lines like this: let totarmure= +values.totarmure||0; let totaldef; let basedef; let surpridef; The first looks okay, but the rest have no value assigned. Wait, I see an issue. you have multiple declarations like this let totaldef = +values.totarmure||0; let basedef +values.totarmure||0; let surpridef = +values.totarmure||0; let basedef = totref+50; let totaldef= basedef+totarmure; let surpridef= totarmure+50; You are, for example, defining basedef twice - you cannot do that. It doesn't matter if their values are valid, two let statements with the same variable name will cause a crash. See Vince's replacement code. Notice how let isn't used for the last 3 lines.
Omg my lords and saviors This works as fire, thank you both so much, for the code and the explanations. I'm so happy !
Hello again, I am now done with HTML and Sheetworkers and focusing on CSS. There is one thing I am struggling with : I want to change the color of a selected option in a list. I managed to change the colors of the options on the drop down list, but when the option is selected, the color remains black, as you can see on this picture, "Confirmé" is blue when I'm selecting, but once I clicked it is still black. I don't know if it is possible to do what i want without using sheetworkers, I would like not to since it would require a lot of work, i have like 20 or 25 menus to change like this. Here are my html and css. &lt;select name="attr_lvlfor" class="skillmaj"&gt; &nbsp; &lt;option value="0" class="lvln"&gt;Novice&lt;/option&gt; &nbsp; &lt;option value="5" class="lvli"&gt;Initié&lt;/option&gt; &nbsp; &lt;option value="10" class="lvlc"&gt;Confirmé&lt;/option&gt; &nbsp; &lt;option value="15" class="lvle"&gt;Expert&lt;/option&gt; &nbsp; &lt;option value="20" class="lvlm"&gt;Maître&lt;/option&gt; &nbsp; &lt;/select&gt; ------- option.lvln { color: #9c9c9c; } option.lvli { color: #32803a ; } option.lvlc { color: #2260d4; } option.lvle { color: #6a05a8 ; } option.lvlm { color: #d4a004 ; } I tried this code below to fix my issue but it doesn't seem to have any effect... .skillmaj option[value="0"] { color: #9c9c9c; } .skillmaj option[value="5"] { color: #32803a; } .skillmaj option[value="10"] { color: #2260d4; } .skillmaj option[value="15"]{ color: #6a05a8; } .skillmaj option[value="20"] { color: #d4a004; } Thank you for reading me !
1702568544

Edited 1702590227
GiGs
Pro
Sheet Author
API Scripter
It sounds like you want to change the colour of the selected value, after it has been selected? You can do this by setting a class on the select (not the optons, but the select itself), and have CSS declarations to target that class and value. If your 20+ other things use the same colour scheme and values, you can use the same class. Your HTML &lt;select name="attr_lvlfor" class="skillmaj"&gt; &nbsp; &lt;option value="0" class="lvln" selected&gt;Novice&lt;/option&gt; &nbsp; &lt;option value="5" class="lvli"&gt;Initié&lt;/option&gt; &nbsp; &lt;option value="10" class="lvlc"&gt;Confirmé&lt;/option&gt; &nbsp; &lt;option value="15" class="lvle"&gt;Expert&lt;/option&gt; &nbsp; &lt;option value="20" class="lvlm"&gt;Maître&lt;/option&gt; &nbsp; &lt;/select&gt; This has a class already which makes things easier. .skillmaj[value="0"] { color: #9c9c9c; } .skillmaj[value="5"] { color: #32803a; } .skillmaj[value="10"] { color: #2260d4; } .skillmaj[value="15"] { color: #6a05a8; } .skillmaj[value="20"] { color: #d4a004; } I added selected to the select, because this sets a default. I think it's always a good idea to set a default value with selects.
Thank you for answering, I did what you just said, even when i copy/paste your code, it doesn't change the colour after it has been selected, colour remains black Do you have an idea why it doesn't change ?
Sorry if I sounded rude, I didn't meant to, on the opposite I'm really glad you can help me with this and i'm really grateful for that. Thing is my english is not the best and i may sometimes sound awkward typing here
1702587878

Edited 1702588903
GiGs
Pro
Sheet Author
API Scripter
Don't worry, I don't mind being terse. I am terse too. This has reminded me that conditional styling on selects is very hard. The best way I can think to do it create a hidden input with the same name as the select, give it a class, and use the conditional styling rule. So your HTML would be changed to something like: &lt; input type= "hidden" name= "attr_lvlfor" class= "skillmaj" value= "0" &gt; &lt; select name= "attr_lvlfor" class= "skillmaj" &gt; &nbsp; &lt; option value= "0" class= "lvln" selected &gt; Novice &lt;/ option &gt; &nbsp; &lt; option value= "5" class= "lvli" &gt; Initié &lt;/ option &gt; &nbsp; &lt; option value= "10" class= "lvlc" &gt; Confirmé &lt;/ option &gt; &nbsp; &lt; option value= "15" class= "lvle" &gt; Expert &lt;/ option &gt; &nbsp; &lt; option value= "20" class= "lvlm" &gt; Maître &lt;/ option &gt; &lt;/ select &gt; Notice the hidden input - this must be before the select. It has the same name, so that its value is the same as the select. It is given a class that can be anything. I've chosen the same classname as the select because then we can do this: .skillmaj [ value = "0" ] + .skillmaj { color : #9c9c9c ; } .skillmaj [ value = "5" ] + .skillmaj { color : #32803a ; } .skillmaj [ value = "10" ] + .skillmaj { color : #2260d4 ; } .skillmaj [ value = "15" ] + .skillmaj { color : #6a05a8 ; } .skillmaj [ value = "20" ] + .skillmaj { color : #d4a004 ; } Notice here that the first skillmaj refers to the hidden input, the second to the select. If you want the hidden input to not be directly next to the select, change the + to a ~, like so .skillmaj [ value = "0" ] ~ .skillmaj { color : #9c9c9c ; } .skillmaj [ value = "5" ] ~ .skillmaj { color : #32803a ; } .skillmaj [ value = "10" ] ~ .skillmaj { color : #2260d4 ; } .skillmaj [ value = "15" ] ~ .skillmaj { color : #6a05a8 ; } .skillmaj [ value = "20" ] ~ .skillmaj { color : #d4a004 ; } If there's an easier way to do this, I'm all ears!
It works ! Thank you so much And I'm using it for the other 20+ menus, I only have to make a few changes but I tried it and it works perfectly too
1702608092
GiGs
Pro
Sheet Author
API Scripter
Great!