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 .
×

[Homebrew] Help with a sheet worker

Greetings! I am at about 90% with my sheet worker. But the last percentages are giving me a headache. Hopefully one of you can help me with this. Here is a block of my skills: <div class="AttributZeile"> <label>Weisheit:</label> <input type="number" name="attr_Weisheit" value="0" /> <button type="roll" value= "&{template:custom} {{title=Probe auf Weisheit}} {{subtitle=@{character_name}}} {{Ergebnis=[[ [[floor([[[[@{Weisheit}]] / 3]])]]d6 + [[[[@{Weisheit}]] % 3]] + [[floor([[[[?{Modifikator|0}]] / 3]])]]d6 + [[[[?{Modifikator|0}]] %3]] - ?{Malus|0}]] }} {{Wert=@{Weisheit}}} {{Modifikator=?{Modifikator}}} {{Malus=?{Malus|0}}}" name="roll_WeisheitProbe"></button> </div> <div class="FertigkeitZeile"> <input type="text" value="Astronomie" name="attr_AstronomieName" readonly /> <input type="number" name="attr_AstronomieWert" value="0" /> <input type="text" name="attr_AstronomieAttribut" value="Weisheit" readonly /> <input type="text" name="attr_AstronomieAttributBonus" value="5" readonly /> <input type="text" name="attr_AstronomieGesamt" value="0" readonly /> <button type="roll" value= "&{template:custom} {{title=Probe auf @{AstronomieName}}} {{subtitle=@{character_name}}} {{Ergebnis=[[ [[floor([[[[@{AstronomieGesamt}]] / 3]])]]d6 + [[[[@{AstronomieGesamt}]] % 3]] + [[floor([[[[?{Modifikator|0}]] / 3]])]]d6 + [[[[?{Modifikator|0}]] %3]] - ?{Malus|0}]] }} {{Wert=@{AstronomieWert}}} {{Modifikator=?{Modifikator}}} {{Malus=?{Malus|0}}}" name="AstronomieProbe"></button> </div> Here is the sheet worker: <script type="text/worker"> const eigenschaften = ["Stärke", "Geschick", "Konstitution", "Wahrnehmung", "Willenskraft", "Weisheit", "Charisma"]; const fertigkeiten = ["Einhandwaffen", "Zweihandwaffen", "Waffenlos", "Bogen", "Armbrust", "Wurfwaffen", "Athletik", "Ausweichen", "Klettern", "Reiten", "Schleichen", "Schwimmen", "Taschendiebstahl", "Unempfindlichkeit", "Konzentration", "Orientierung", "Sinnenschärfe", "Spurensuche", "Betören", "Etikette", "Gassenwissen", "Handeln", "Menschenkenntnis", "Überreden", "Alchemie", "Astronomie", "Erste Hilfe", "Fallenkunde", "Geographie", "Geschichte", "Götter_Kulte", "Kriegskunst", "Magiekunde", "Mathematik", "Pflanzenkunde", "Rechtskunde", "Sagen_Legenden", "Staatskunst", "Tierkunde", "Wappenkunde", "Wettervorhersage", "Wildnisleben"]; fertigkeiten.forEach(function (fertigkeit) { on(`change:${fertigkeit.toLocaleLowerCase()}wert change:${eigenschaften} sheet:opened`, function () { getAttrs([`${fertigkeit}Attribut`, `${fertigkeit}Wert`, `${eigenschaften}`], function (v) { const welches_attribut = String(v[`${fertigkeit}Attribut`]); const attribut_bonus = parseInt(v[welches_attribut]) || 0; const fertigkeit_wert = parseInt(v[`${fertigkeit}Wert`]) || 0; const gesamt = attribut_bonus + fertigkeit_wert; setAttrs({ [`${fertigkeit}AttributBonus`]: attribut_bonus, [`${fertigkeit}Gesamt`]: gesamt }); }); }); }); </script> The value entered by the player ("AstronomieWert"). Is correctly transferred to the cell Total ("AstronomieGesamt"). And my starting value for AttributeBonus of 5 is overwritten with 0. Just as I have provided for the emergency. So I would say that the problem lies somewhere around the recognition of the attributes. I hope I have expressed myself understandably, otherwise please ask. Kind regards!
1651614875
GiGs
Pro
Sheet Author
API Scripter
This change:${eigenschaften} won't do what you want (nor will the related section in getAttrs). You are trying to get a single attribute, but that variable contains an array of attributes so you need to get them in a different way. This looks familiar, and I think I have given you earlier code that solves this problem. So I'd look at my previous replies. BBut here's another solution: const eigenschaften = [ "Stärke" , "Geschick" , "Konstitution" , "Wahrnehmung" , "Willenskraft" , "Weisheit" , "Charisma" ]; const fertigkeiten = [ "Einhandwaffen" , "Zweihandwaffen" , "Waffenlos" , "Bogen" , "Armbrust" , "Wurfwaffen" , "Athletik" , "Ausweichen" , "Klettern" , "Reiten" , "Schleichen" , "Schwimmen" , "Taschendiebstahl" , "Unempfindlichkeit" , "Konzentration" , "Orientierung" , "Sinnenschärfe" , "Spurensuche" , "Betören" , "Etikette" , "Gassenwissen" , "Handeln" , "Menschenkenntnis" , "Überreden" , "Alchemie" , "Astronomie" , "Erste Hilfe" , "Fallenkunde" , "Geographie" , "Geschichte" , "Götter_Kulte" , "Kriegskunst" , "Magiekunde" , "Mathematik" , "Pflanzenkunde" , "Rechtskunde" , "Sagen_Legenden" , "Staatskunst" , "Tierkunde" , "Wappenkunde" , "Wettervorhersage" , "Wildnisleben" ]; fertigkeiten . forEach ( function ( fertigkeit ) {   on ( `change: ${ fertigkeit . toLocaleLowerCase () } wert ${ eigenschaften . map ( stat => `change: ${ stat , toLowerCase () } ` ). join ( ' ' ) } sheet:opened` , function () {     getAttrs ([ ` ${ fertigkeit } Attribut` , ` ${ fertigkeit } Wert` , ... eigenschaften ], function ( v ) {       const welches_attribut = v [ ` ${ fertigkeit } Attribut` ];       const attribut_bonus = parseInt ( v [ welches_attribut ]) || 0 ;       const fertigkeit_wert = parseInt ( v [ ` ${ fertigkeit } Wert` ]) || 0 ;       const gesamt = attribut_bonus + fertigkeit_wert ;       setAttrs ({         [ ` ${ fertigkeit } AttributBonus` ]: attribut_bonus ,         [ ` ${ fertigkeit } Gesamt` ]: gesamt       });     });   }); }); Note you don't need String(), because all attributes in roll20 are saved as strings. The attributes are already strings.
1651643599

Edited 1651643609
Yes, exactly, I took your suggestions and wrote my own version to understand the whole thing better. Unfortunately, your suggestion doesn't work. :( And to understand your changes, here are two more questions: 1. what exactly does this part "${properties.map(stat => `change:${stat,toLowerCase()}`).join(' ')" do? 2. and what does "...eigenschaften" mean in the GetAttrs function? Thanks a lot for your help. :)
1651645882

Edited 1651646254
GiGs
Pro
Sheet Author
API Scripter
I see the likely culprit. This: eigenschaften.map(stat => `change:${stat,toLowerCase()}`).join(' ') should be eigenschaften.map(stat => `change:${stat.toLowerCase()}`).join(' ') I typed a , instead of a . What this does: its a map function then a join function. The map function: .map(stat => `change:${stat.toLowerCase()}`) takes an array (eigenschaften), and does something to every item in the array. It does this to every item in the array: `change:${stat.toLowerCase()}` In otherwords, it changes an item from Stärke to change:stärke So after the map runs, you have an array with changed entries. But an array is no good - you need a string of words. The join function converts an array into a string, with whatever is inside the brackets used as a separator. So this .join(' ') joins that array into a string of words, separated by spaces. Finally putting the whole thing inside ${ } is something you can do inside a ` ` string - the ${ } is a script block and lets you include variables and code inside a string. This only works in a string using backticks ` `, not the usual quotes " or '. So in summary, that section converts the array into the format you need for on('change') line. The second question is a lot shorter to answer: ... is the spread operator, and it "spreads out" an array into its individual items. In your getAttrs line you have an array getAttrs(['this is an array']) , and dropping the full array eigenschaften into that wont work, as you then have an array inside an array. You need the individual items, and ...eigenschaften gives the individual items. I hope that helps!
It works! Thank you very much! I am so happy right now. :D
And thank you for the explanations, that helps me a lot too. :) Do you have Paypal or something? I would like to show my appreciation for all your help.
1651646481
GiGs
Pro
Sheet Author
API Scripter
Thank you! I'm sending my paypal in IM (I think roll20 will frown on us posting that kind of think publically, though my patreon is linked at my blog cybersphere.me)