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

Checking that two attribute values are above a minimum value in calculation

Hello, me again! Spurred on by the previous help, I am now looking at ways to set an attribute value if two variables are above a certain number. For example, both "value_pr_1" and "value_pr_2" need to be 16 or higher in order to set "10" in the attribute "ExpPercentage". I have tried many different ways and just can't get it to work (might be the lateness of the hour ...). If a kind soul could push me in the right direction, it would be greatly appreciated. Thanks!       } else if (["class"].indexOf( values.class.toLowerCase()) >= 0) {     var value_pr_1 = parseInt(values["final_con"])||0;     var value_pr_2 = parseInt(values["final_str"])||0; if(value_pr_1 > 15, value_pr_2 > 15 ) { setAttrs({ ExpPercentage: "10" }); } else if(value_pr_1 > 12 ) { setAttrs({ ExpPercentage: "5" }); } else if(value_pr_2 > 12 ) { setAttrs({ ExpPercentage: "5" });     } else { setAttrs({ ExpPercentage: "0" }); } }
1647738186
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
To combine two expressions in an if, you need to use the logical operators . I'd recommend running through a JS overview.
1647738339
vÍnce
Pro
Sheet Author
if(value_pr_1 > 15 && value_pr_2 > 15 ) { setAttrs({ ExpPercentage: "10" });        }
Brilliant, thanks! My brain just wasn't seeing things logically!
1647803807
GiGs
Pro
Sheet Author
API Scripter
I'd also recommend saving the value into a variable, and then doing one setAttrs at the end. Your current code wont cause problems, but teaches bad habits that will cause you problems later. You should only ever call setAttrs once in a sheet worker. The fact this is inside an if else statement suggests you might be calling it more than once. It's hard to suggest a proper fix without seeing the full sheet worker code, but something like this: // before the if else structure starts:     var exp_percentage = 0; // then the rest of your code     } else if (["class"].indexOf( values.class.toLowerCase()) >= 0) { var value_pr_1 = parseInt(values["final_con"])||0; var value_pr_2 = parseInt(values["final_str"])||0;     if(value_pr_1 > 15, value_pr_2 > 15 ) {     exp_percentage = 10; } else if(value_pr_1 > 12 || value_pr_2 > 12 ) {     exp_percentage = 5;         }     } // then at the end of your sheet worker     setAttrs({         ExpPercentage: exp_percentage     }); You can set multiple attributes at once inside the setAttrs statement, separating them with a comma. I'm also curious about this if statement: if (["class"].indexOf( values.class.toLowerCase()) >= 0) { it looks like you are testing if the class attribute equals 'class' ? If so, you can just do: if (values.class.toLowerCase() === 'class')) { Or to make it easier for debugging: // before if statement begins var class = values.class; console.log('class = ' + class); // this line is optional - but lets you see what class actually equals // code continues here, including the start of your if statement, then else if(class.toLowerCase() === 'class')) {