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

Trying to math attrs and failing

1514070271
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
Trying to output experience totals for a character sheet by grabbing the initial score but its failing to work for me.  on("change:repeating_ability:Ability_Score", function() { getAttrs([repeating_ability_Score], function(values) { var n = values.repeating_ability_Score; setAttrs({ repeating_ability_AbilityTotal_exp: ((n*(n+1)/2)*5), repeating_ability_AbilityAdvancement_exp: ((n+1)*5); }); }); }); And in case it matters, the relevant line in the repeating fieldset <input type="number" class="sheet-number_2" name="attr_Ability_exp" value="0"/> / <input type="number" class="sheet-number_2" name="attr_AbilityAdvancement_exp" value="0"/> / <input type="number" class="sheet-number_2" name="attr_AbilityTotal_exp" value="0"/>
1514070708

Edited 1514070737
Finderski
Plus
Sheet Author
Compendium Curator
getAttrs pulls things in as a string, so you need something like: var n = parseInt(values.repeating_ability_Score)||0;
1514072475
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
Good to know. It seems right now its not setting the attributes correctly, when I play with the score field its not updating to the exp fields. I was making a wild guess that maybe putting both attributes in the same function might be the problem but that doesn't seem to work either. This is where I'm at now. on("change:repeating_ability:Ability_Score", function() {          getAttrs([repeating_ability_Score], function(values) {         var n = parseInt(values.repeating_ability_Score)||0;         setAttrs({repeating_ability_AbilityTotal_exp: ((n*(n+1)/2)*5)});         setAttrs({repeating_ability_AbilityAdvancement_exp: ((n+1)*5)});     }); });
1514079215

Edited 1514092026
GiGs
Pro
Sheet Author
API Scripter
I see a couple of problems. This:  on("change:repeating_ability:Ability_Score suggests you have field names repeating_ability_Ability_Score but later you use "repeating_ability_Score" - those two fields don't match up. Also, in the change line, you can't use capitals, so that first line should be one of these: on("change:repeating_ability:ability_score // or on("change:repeating_ability:score // so this line var n = parseInt(values.repeating_ability_Score)||0; // might be wrong, and maybe should be var n = parseInt(values.repeating_ability_Ability_Score)||0; I cant tell which of those statements is correct, and which one's wrong, without seeing the repeating set's html. Btw, you still use capital letters in the other places, but you must drop everything to lower case in the on() line. Your SetAttrs statements should also be combined, like this: setAttrs({ repeating_ability_AbilityTotal_exp: ((n*(n+1)/2)*5),      repeating_ability_AbilityAdvancement_exp: ((n+1)*5) }); Also, another syntax note. In your first post, you had this: setAttrs({ repeating_ability_AbilityTotal_exp: ((n*(n+1)/2)*5), repeating_ability_AbilityAdvancement_exp: ((n+1)*5); }); That semi-colon inside the setattrs brackets shouldn't be there. Refer back to the version I posted just above.
1514104105

Edited 1514104239
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
I've made the suggested changes, still no bueno T_T I'm going to post the full fieldset then.  The relevant attributes: attr_Ability_Score attr_AbilityAdvancement_exp attr_AbilityTotal_exp <fieldset class="repeating_ability">                     <table class="sheet-table_2" style="width:400px;">                         <tr>                             <td width="30px"><button type="roll" class="sheet-button" name="roll_ability" value="&{template:ability} {{name= @{character_name}}} {{label4=Circumstances}} {{result4=[[(?{Circumstantial|0})]]}} {{label0=@{Ability_name}}} {{banner=@{Ability_Speciality}}} {{label1=Rank}} {{result1= [[ @{Ability_Score} + @{Ability_Puissant} ]]}} {{label2=Characteristic}} {{result2=[[@{Ability_Characteristic}]]}} {{label3=Weakness}} {{result3=[[@{Fatigue} + @{wound_total}]]}} {{result0=[[ 1d10 + @{Ability_Score} + @{Ability_Puissant} + @{Ability_Characteristic} + @{wound_total} + @{Fatigue} + (?{Circumstantial|0})]]}}"></button></td>                                                         <td width="240px"><input type="text" style="width:220px;" class="sheet-heading_4" name="attr_Ability_name"/></td>                             <td><input type="number" class="sheet-number_2" name="attr_Ability_TotalScore" value="[[(@{Ability_Score}) + (@{Ability_Puissant})]]" disabled="true" /></td>                             <th><div style="width:40px;"><input type="checkbox" class="sheet-hider sheet-checkbox_1" name="attr_Ability_show" value="1" checked/><span></span></div></th>                         </tr>                     </table>                     <input type="checkbox" class="sheet-hider sheet-hidden" value="1" name="attr_Ability_show" checked/>                     <div class="sheet-hide">                         <table class="sheet-table_2" style="width:400px;">                             <tr>                                 <th>Characteristic</th>                                 <th>Speciality</th>                                 <th>Score</th>                                 <th>Bonus</th>                             </tr>                             <tr>                                 <td>                                     <select class="sheet-select_1" name="attr_Ability_Characteristic">                                         <option class="sheet-italic" value="0">Characteristic</option>                                         <option value="@{Intelligence_Score}">Intelligence</option>                                         <option value="@{Perception_Score}">Perception</option>                                         <option value="@{Strength_Score}">Strength</option>                                         <option value="@{Stamina_Score}">Stamina</option>                                         <option value="@{Presence_Score}">Presence</option>                                         <option value="@{Communication_Score}">Communication</option>                                         <option value="@{Dexterity_Score}">Dexterity</option>                                         <option value="@{Quickness_Score}">Quickness</option>                                     </select>                                 </td>                                 <td><input type="text" class="sheet-heading_4" name="attr_Ability_Speciality" placeholder="Speciality" /></td>                                 <td><input type="number" class="sheet-number_2" name="attr_Ability_Score" value="0"/></td>                                 <td><input type="text" class="sheet-number_2" name="attr_Ability_Puissant" value="0"/><span></span></td>                             </tr>                             <tr>                                 <th style="text-align: right;">XP</th>                                 <td colspan="3">[<input type="number" class="sheet-number_2" name="attr_Ability_exp" value="0"/> / <input type="number" class="sheet-number_2" name="attr_AbilityAdvancement_exp" value="0"/> / <input type="number" class="sheet-number_2" name="attr_AbilityTotal_exp" value="0"/>]</td>                             </tr>                         </table>                     </div>                 </fieldset> Here's the present script on("change:repeating_ability:ability_score", function() {     getAttrs([repeating_ability_Ability_Score], function(values) {         var n = parseInt(values.repeating_ability_Ability_Score)||0;         setAttrs({             repeating_ability_AbilityTotal_exp: ((n*(n+1)/2)*5),             repeating_ability_AbilityAdvancement_exp: ((n+1)*5)         });     }); });
1514108399
Jakob
Sheet Author
API Scripter
    getAttrs(['repeating_ability_Ability_Score'], function(values) { You want the string 'repeating_ability_Ability_Score', not the value of an (undefined) repeating_ability_Ability_Score variable.
1514154000
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
ITS A CHRISTMAS MIRACLE. Thanks everyone, you save me again. 
1514166118

Edited 1514168839
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
Can I set values to attributes that I've spliced together like this? on("change:creo_score change:intellego_score change:muto_score change:perdo_score change:rego_score change:animal_score change:aquam_score change:auram_score  change:corpus_score change:herbam_score change:ignem_score change:imaginem_score change:mentem_score change:terram_score change:vim_score", function(eventInfo)) {     var art = eventInfo.sourceAttribute;     getAttrs([art], function(values)) {         var n = parseInt(values.art)||0;         setAttrs({             art + "_exp" = (n+1),             art + "_exp2" = (n*(n+1)/2)         });     }); }); The idea being that I can find the root attribute and make changes to attributes based off the of the root. 
1514207463

Edited 1514215637
Jakob
Sheet Author
API Scripter
Can I set values to attributes that I've spliced together like this? Absolutely, if you want calculated property names in object literals, you just need to wrap them in square brackets like this (and no equal signs, that is not how object literals work). However, values.art will access the property name "art"; instead, you will want to use values[art].         var n = parseInt(values[art])||0; setAttrs({             [art + "_exp"]: (n+1),             [art + "_exp2"]: (n*(n+1)/2)         }); You could also register one event per attribute: ['creo', 'intellego', 'muto', 'perdo', 'rego', 'animal', 'aquam', 'auram', 'corpus', 'herbam', 'ignem', 'imaginem', 'mentem', 'terram', 'vim'].forEach(function (name) { on("change:" + name + "_score", function () {     getAttrs([name + "_score"], function(values) { const n = parseInt(values[name + "_score"])||0;       setAttrs({             [name + "_score_exp"]: (n+1),             [name + "_score_exp2"]: (n*(n+1)/2)       });     }); }); });