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

table instead of "if" conditions

Hello everyone. For my homebrew campain, I have a macro to generate a certain amount of HP and MP when I create NPC according to their attribute (e.g. constitution 5 -> +35 HP ; intelligence 4 -> +20 MP). It work quite fine with "if" conditions in a powercard, but it takes about 30 seconds each time to read every condition. Is there a way to make the macro look up the HP value for one attribute level in a table instead of checking every level until it finds the good one ? I don't know if I'm clear and my script skills are really poor. I didn't find and APi to do the trick so if you know one, Please enlight me. Thank you
1598291278
David M.
Pro
API Scripter
Can you give example(s) of the relationships between the attributes and the generated values? I'm assuming the relationship is something more complicated than a simple formula, since otherwise you could just put the formula into the macro using the attribute as input. e.g. for HP--->   [[ 10 + @{selected|constitution}*5 ]] , or whatever the math works out to? Option 2: Going the Lookup route. You have a Pro sub, api scripts are an option. TheAaron wrote an api script a while ago called lookup that does just that: it outputs the value of a rollable table given an index (item number) Syntax is as follows: !lookup TableName Index Here's  the link to the code. The downside of this method is that you are limited to the output formatting of the script, and can't just insert the script output into some existing output template.
1598292382

Edited 1598293134
In fact it's just that I can't add factorial numbers : for a each point of constitution the character gain (1d10 + (const. lvl)) HP. So for example : const. lvl 5 -> (5d10 + !5) = (5d10 + 1 + 2 + 3 + 4 + 5 ). It's not difficult to say at lvl 5 it's 5d10 + 15 but the bonus changes for each lvl. I did it with a powercard and with a condition for every lvl under 10 but it's really heavy. I was looking for a way to simplify it.
' !power {{ ' --whisper|GM ' --format|heal ' --name|**@{selected|character_name}** possede ' --leftsub|CON : @{selected|Constitution} ' --rightsub|REF : @{selected|Reflexion} ' -- ?? @{selected|Constitution} == 1 ?? PV *1|[[ 1d10 + 1 ]] ' -- ?? @{selected|Constitution} == 2 ?? PV *2|[[ 2d10 + 3 ]] ' -- ?? @{selected|Constitution} == 3 ?? PV *3|[[ 3d10 + 6 ]] ' -- ?? @{selected|Constitution} == 4 ?? PV *4|[[ 4d10 + 10 ]] ' -- ?? @{selected|Constitution} == 5 ?? PV *5|[[ 5d10 + 15 ]] ' -- ?? @{selected|Constitution} == 6 ?? PV *6|[[ 6d10 + 21 ]] ' -- ?? @{selected|Constitution} == 7 ?? PV *7|[[ 7d10 + 28 ]] ' -- ?? @{selected|Constitution} == 8 ?? PV *8|[[ 8d10 + 36 ]] ' -- ?? @{selected|Constitution} == 9 ?? PV *9|[[ 9d10 + 45 ]] ' -- ?? @{selected|Reflexion} == 1 ?? PM *1|[[ 1d6 + 1 ]] ' -- ?? @{selected|Reflexion} == 2 ?? PM *2|[[ 2d6 + 3 ]] ' -- ?? @{selected|Reflexion} == 3 ?? PM *3|[[ 3d6 + 6 ]] ' -- ?? @{selected|Reflexion} == 4 ?? PM *4|[[ 4d6 + 10 ]] ' -- ?? @{selected|Reflexion} == 5 ?? PM *5|[[ 5d6 + 15 ]] ' -- ?? @{selected|Reflexion} == 6 ?? PM *6|[[ 6d6 + 21 ]] ' -- ?? @{selected|Reflexion} == 7 ?? PM *7|[[ 7d6 + 28 ]] ' -- ?? @{selected|Reflexion} == 8 ?? PM *8|[[ 8d6 + 36 ]] ' -- ?? @{selected|Reflexion} == 9 ?? PM *9|[[ 9d6 + 45 ]] ' }}
1598296934

Edited 1598297014
David M.
Pro
API Scripter
Looks like a triangular number formula would work, so calculated values would be: Nd# + N*(N+1)/2 . Try replacing all of your conditionals with these two lines: --PV [[ @{selected|Constitution}d10 + @{selected|Constitution}*(@{selected|Constitution}+1)/2 ]] --PM [[ @{selected|Reflexion}d6 + @{selected|Reflexion}*(@{selected|Reflexion}+1)/2 ]]
Thank you very much. So simple. I wish I knew that in high school.