Interesting comments in the Using Snippets pinned thread and I wanted to explore it further. Presented an interesting challenge was @Kitsune96 in comment #729. Basically they wanted this:

Level 1-4: 1d6{{modifier:cha}}

Level 5-9: 1d10{{modifier:cha}}

Level 10-14: 2d12{{modifier:cha}}

Level 15 and up: 3d12{{modifer:cha}}

Since this was a racial feature, you couldn't just use {{scalevalue}} like in a subclass. We have to break this down into different parts: number of dice + "d" + die type + {{modifier:cha}}. Luckily the challenge had a simple level progression to work with, just some change every 5 levels at 5, 10, and 15, so that made solving this a lot easier.

I looked at the number of dice first since it was incremental changes of a value by 1so it was the simpler of the two. With the incremental changes in number of dice happening at levels 10 and 15, we need to divide our character level by their greatest common factor (GCF), which happens to be 5. This gives us a new value to do stuff. From levels 1 through 4 that value is 0.something, levels 5-9 its 1.something, 10-14 its 2.something, 15-19 its 3.something, and at level 20 its 4. At this point we can apply the modifiers to give these new values a ceiling and a floor. Min:1 says nothing can be smaller than a 1 while max:3 says nothing can be higher than a 3. We'll also round down because whole numbers are sexy. This gives us this simple math:

{{(characterlevel/5)@min:1,max:3,rounddown}}

So now levels 1 through 9 will display a 1 in this snippet, levels 10-14 will display a 2, and levels 15 and above will display a 3.

I started looking at the second half of the challenge, die type. It's on a similar incremental structure. Our GCF is still 5, so we'll still divide character level by that, but it's the value that isn't a regular pattern going from 6, to 10, to 12. I was trying to figure out to make that work. I opened notepad and typed out 20 lines of level and desired result, then added a column for different calculation results. I probably should have just opened google sheets or something. I had tested little changes here and there in the structure. I used 9 custom actions, since I wanted to display the changes at 8 different levels, one to replicate each: 1, 4, 5, 9, 10, 14, 15, 19, and 20. I was getting close but couldn't quite wrap my head around it at work. Then I refreshed the forum and saw @Halfwing's attempt at it. After a copy paste glitch, he posted this:

{{((characterlevel/5)@rounddown*4)@max:6+6}}

I pasted it in each of my 9 custom actions and changed characterlevel to the number I was testing in that action and it returned the correct value at each of the checkpoints. I'm obsessed over how this works.

He divides the level by the GCF and then round's down to get a new value. This gives levels 1 through 4 that value is 0, levels 5-9 its 1, 10-14 its 2, 15-19 its 3, and at level 20 its 4. Similar to where I was, just applying rounding now since we're not applying the min or max modifiers yet. These should be referred to as our initial values.

Then multiply that value by 4, so levels 1-4 the value is still 0, 5-9 the value is 4, 10-14 the value is 8, 15-19 the value is 12, and at level 20 the value is 16. This will give us our working values. Why did he multiply by 4?

The die type changes at levels 5 and 10 going from a 6 to a 10 to a 12. For levels 1-4 our working value is 0. Simple enough:

0 * 4 + 6 0 + 6 6

So somewhere down the line we need to add 6 to all our values to get what we want to achieve at each character level. For levels 5 and up, it needs to be a 10 or 12. 10 - 6 = 4. I mean, maybe. No? It's deeper than that and that deepness comes from the initial values. Looking at our initial values 1-4 is 0, 5-9 is 1, 10 and up is 2(or more). What we want to do is add to that +6 we're gonna tack on at the end to get 10. For levels 5-9 we'll see why the 4 multiplier is necessary:

EDIT: Check comment #4 as to why we're looking to add that +6(hint it's the value if the starting die type)

1 * 4 + 6 4 + 6 10

For levels 10 and up it's:

2(or more) * 4 + 6 8(or more) + 6 14(or more)

Since there's not another increment change above 10, we just need to throw a max in there. Since the last step is adding a 6 and our goal is 12, we can only have a max of 6. Mentioned before when we multiplied by 4 to calculate our working values: 10-14 the value is 8(max 6), 15-19 the value is 12(max 6), and at level 20 the value is 16(max 6). And:

6 + 6 12

So now we can solve for both parts and successfully snippeted TF outta this challenge resulting in:

Maybe I'm obsessed, maybe I'm a nerd. YOU PLAY D&D, NERD! But I really loved not only trying to solve it but exploring the actual solution. I didn't want to crowd the Using Snippet thread with my inebriated ramblings. I just love you guys so much!!!!! Wait, wrong inebriation.

EDIT - added some RTF to show where the different values came from

Seeing a full breakdown of the math behind the code is always pleasing to me (I'm a math nerd myself). Although I figured out the main equation, it was a logarithmic equation, which DND Beyond does not have implementation at this time. I couldn't figure out a way to simplify the expression to make everything work. Happy to see that my question sparked a new thread! Thanks again for your help and @Halfwing's help :D

I know that we can add snippets to custom actions. I have a player that uses magical playing cards that they can throw. At certain levels the damage increases.

1st - 7th level it deals 1d4+Dex slashing damage

8th - 12th level is deals 1d6+Dex slashing damage

13th+ level deals 1d8+Dex slashing damage

How can I modify that snippet so that it will automatically adjust using this information?

I knew it could be done with enough trial and error, but difficult. With the incremental changes coming at the odd levels of 8 and 13, it is not easily divisible. You can't use the greatest common factor (GCF) as they don't share any factors other than 1. The changes are continuous though going from a d4 to a d6, to a d8. Here's what I came up with:

Here we're taking characterlevel and dividing by 8, the max will be 1 (catching anything over level 16). Multiply that by 2. So levels 1-7, divided by 8 and rounded down to 0 times 2 is 0. Levels 8 and up, divided by 8 and be rounded down to 1 times 2, so 2.

So 4 plus 0 or 2. Then we add:

(classlevel/13)@rounddown*2

or

(characterlevel/13)@rounddown*2

Here we divide by 13. No maximum is necessary here since you'd have to be level 26 to screw the snippet, which isn't possible. Round the result down and multiply by 2. So levels 1-12, divided by 13 and rounded down will be 0 times 2 which is 0. Levels 13 and up, divided by 13 will be 1 times 2, which is 2.

So 4 plus 0 or 2 plus 0 or 2 gives us a 4, a 6, or an 8 depending on what level we're at. We close up the snippet, throw the bells and whistles on it:

So it looks like there's a limited amount of PEDMAS implemented as inside the parenthesis (classlevel/8)@max:1,rounddown*2 is resolved with it's max and rounddown modifiers before multiplying by 2, but this is also being read left to right. All of this is calculated before the initial 4+ at the beginning of the snippet so there's some PEDMAS in there, but you cannot get complicated.

Using a fully implemented PEDMAS, ((classlevel/8)@max:1,rounddown+(classlevel/13)@roundddown)*2+4should work, but it throws an error. As you can see we're getting complicated with nested parenthesis. I'm starting to think think that nested parenthesis aren't supported so that's going to make calculations lean on a left to right reading, with at least some PEDMAS to give a little priority to things. See comment #5 on my new theory regarding this.

One thing I'm noticing when it comes to snippets displaying a dynamic type of die to use, ie. d4, d6, d8, etc, these more complicated snippets are starting (or ending) calculations with the default value. Comment #3 explores a snippet that adds 4 to some stuff. @Halfwing's portion of OP added a 6 to everything at the end. These are the lowest die types used in the snippet, a d4 and a d6 respectively. Getting the calculated value from a modifier, just needs to be reduced in such a way to add to that lowest die. Whether we're dividing by the GCF or any random level, we just want to get to the incremental change away from that first (or last) value.

Exploring another snippet I was very impressed with the first time I saw it. It's not mine, but I totally use it as a great way to calculate minutes you can hold breath in my Stats (Suffocation) feat and is in the Jump & Suffocation stats link in my signature (credit given to Glazia in that comment). They came up with this:

A creature can hold its breath for a number of minutes equal to 1 + its Constitution modifier (minimum of 30 seconds).

So using PEDMAS, this totally makes sense. Add a 1 to to your CON. There is a minimum of 30 seconds, or 0.5 minutes, which is what the snippet produces if your CON modifier is -1 or lower. So we're adding 1 to our CON modifier and multiplying by 2 then dividing by 2, basically this allows us to turn any 1 into half, or 0.5.

So if your CON modifier is 0, we're adding 1 inside the first parenthesis then multiplying by 2. THIS number we want a minimum of 1. So 0+1 then times 2 gives a 2, but -1 CON modifier or anything more negative, gives a 0 or less, but our minimum is 1 so we end up with 1. Then we divide it all by 2. So that (0 CON mod + 1) * 2 /2 will give us the 1 we're looking for. Same for a +3 CON modifier. Same for a -3 CON modifier (giving us 0.5 minutes, which is correct).

Why does a nested parenthesis work here, but not in the solution for comment #3? It might be related to how the snippet modifiers are implemented. This example has @min and #unsigned outside of the nested parenthesis, but my first try in comment #3 had the @max and @rounddown on the inside some nested parenthesis before applying the next bit of math. Maybe the snippet modifiers can't be inside a set of parenthesis when applying later calculations. Knowing this could be useful when building snippets.

The solution I have for #3 needed the @rounddown applied before multiplying by 2, because just for level 7, if we remove @rounddown we'll have 4 + 0.875+0.5384615.... which ends up being 4+1.4134615.... or 5.somthing which is not the result I wanted. By breaking out the *2 portion on the divided by 8 and the *2 portion of the divided by 13 portion, we have to round down each to get the desired result.

So the first part is calculating the number of damage dice. The last break in the iteration happens at level 13, but at level 7 we have an additional jump from 1 die to 2. But it goes back to 1 die at level 9. So we've got an irregular pattern here. Its probably easier to visualize broken down with each section on a new line:

The first thing we have is a 1 because we're starting with 1 damage die. The next iteration of change happens at level 7. At level 7 we change from 1 die to 2 dice, so we want to add 1 to our starting 1. We divide our character level by 7 and add that to our starting 1. Any characterlevel less than 7 is going to divide and rounddown to 0, so adding this for character levels under 7 is just going to add a 0, otherwise it'll add a 1. We put a max on here because levels 14 and up throw off the math and we're not ready for those levels yet.

The at level 9 we want to reduce that number of dice from 2 back down to a 1. We do the same trick of dividing our characterlevel by 9. Anything less than that rounded down is a 0. We stick a max on here too because level 18 throws off the math again. We subtract this from where we're at, again character levels less than 9 divide and rounddown to 0, subtracting nothing.

Finally we're going to bump the number of dice back up from 1 to 2. We do the same trick of dividing by the characterlevel the change is going to happen. Anything less adds 0, anything more adds a 1.

Basically what we're doing here is starting with an initial value and by dividing our current character level by our iteration points giving us a level switch to work with giving us a 0 or 1. we can add or subtract. Easy, right?

How about the second half of this? I'll go ahead and break it out on a new line for each section

Here we're looking to change the damage die(dice) in an irregular pattern too. The iteration is every 2 levels so there's really not a way to reduce that leaving us to have a calculation at every level change.

At level 1 we start with a d4, so a 4. Using the divide by iteration level and rounddown trick we learned earlier because we're going to be adding and subtracting things again. We need to throw some maximums on here because levels over 10 will cause math problems down the line if we don't put maximums on it. Like earlier if the characterlevel is less than that iteration it'll end up being rounded down to 0.

We are also multiplying each of these iterations. Since we're dividing and roundding down to a 0 or a 1, multiplying this by the change in value will give us a 0 or that change in value. For example, level 3 we're going from a d4 to a d6, so we want to take our level switch (a 0 or a 1) and multiply by 2. We're adding that. We do the same thing at level 5 to push us up to a d8.

Here's the irregular change, at level 7 we're going down to a d4 for that iteration so we want to subtract 4 from that 8. Then at level 9, we're going back up to a d10. So this level switch needs to multiply by 6 and add that to our 4. Bump up by 2 more at level 11.

At level 13, we want to subtract again going from a d12 to a d6. We get our level switch, multiply by 6 and subtract it. Then its just increasing by 2 at levels 15, 17, and 19.

So what did we learn? Level switches are a very useful tool. Basically we divide characterlevel by the iteration point we want, give it a maximum if that level iteration is 10 or under, and rounddown and you have a perfect YES or NO you can multiply by something. 0 multiplied by something will always be 0 so this really helps us adding or subtracting nothing for lower levels but still able to add or subtract something at whatever level you choose.

My solution led to this thread's Do Anything with {{characterlevel}} comment. Basically using some simple level switches to add an subtract each iteration from level to level. Halfwing's solution simplifies that by grouping similar iteration changes together. Halfwing even posted a huge breakdown in order to visualize what needed to change. Let's breakdown the above snippet:

It's probably easier to visualize the first section as (1+characterlevel/2)@roundup*2.

The first group of iterations go from d4 to d6, to d8. Since each of these changes happens every other level (level 1, 3, & 5), we need characterlevel/2 and @roundup to group each pair of levels together (1 & 2, 3 & 4, 5 & 6). This will give us these values for levels 1 through 6: 1, 1, 2, 2, 3, 3. Getting these to the 4, 6, & 8 we want, we need to add 1 to each and then multiply by 2. By putting @roundup outside of the parenthesis of adding that + 1, Halfwing is able to manipulate the order of operations to get the results we need for levels 1, 2, 3, 4, 5, & 6.

Looking over Halfwing's breakdown, you can see this first section of the snippet gives an order of values for all the levels above 7 that we need the remaining sections to calculate. Level 7 we need a level switch to subtract 6 from the first section's value: -(characterlevel/7)@rounddown,max:1*6. That level switch of (characterlevel/X)@rounddown*Y gives us that 0 or 1 value to tell us to subtract nothing if less than X level or subtract 1 times Y. Remember, if X is less than 10, we need to put a max on there because we don't want to subtract more than 6 once we get to 12 and higher. This section gives us the correct results for levels 7 and 8.

Halfwing's visual shows us where the first two sections get us, but we have another change at level 9, going back up to a target of d10. Here we need to use a level switch to add 4 to our current value: +(characterlevel/9)@rounddown,max:1*4. For all the same reasons above, this level switch gets us where we need to be on levels 9, 10, 11, & 12.

The last section need's to subtract 8 from that current value after the 3rd section: -(characterlevel/13)@rounddown*8. Here's another level switch used to subtract something only above a certain level. No need for a maximum value here since this returns a -0 if under level 13.

Most of the heavy lifting on this is in the first section because the last 3 sections are just simple level switches to add or subtract something from that first section result. Breaking out the results in a table and color coding it like Halfwing did really did go a long way to visualize where we needed to go at each step. Manipulating the order of operations is the genius part because multiplying by 2 and adding 1 gives incorrect results but adding 1 and multiplying by 2 gives the right results.

I feel like I missed something. Where are the underlying principles of incremental change and how do we change the up or down.

I feel like it should be graphable. I can put (((x/7)2)+((x/9)2)+3)=y on a graph and get the the points I want

The change up or down would be from leveling up, and/or ASI increases. Since snippet codes are built off of your character's level or modifiers, that's the variable we have to account for and use as our dynamic constant. The math behind the snippet variables needs to account for numbers from -single digits (probably) to +single digits (probably) AND/OR 1 through 20 and different incrementals (PB is 2, 3, 4, 5, 6, whereas levels are 1 through 20). Knowing what the limitations of x are is helpful in building your formula. As is knowing where whole numbers are useful and/or necessary..

Snippet-Master Mairondil, I was working on some homebrew with IamSposta, and he came up with this, for the snippet.

"You have a <strong>1d</strong>{{6+((((characterlevel+1)/6)#rounddown)*2)}} Psionic Energy Die. You can use it to fuel any psionic power you have that use one. Some of your powers expend a Psionic Energy Die, you can’t use a power that requires a die when yours are all expended. Once per long rest you regain this expended Psionic Energy Die at the end of a Short Rest."

However, following that code, it results in a 1d13 at level 20 (admittedly, I have not tried it for the rest of the levels). It's for an effective feat-tree granting Psi-Warriors and Soul Knifes a bit more... jedi-y abilities via more psionic spells.

Snippet-Master Mairondil, I was working on some homebrew with IamSposta, and he came up with this, for the snippet.

"You have a <strong>1d</strong>{{6+((((characterlevel+1)/6)#rounddown)*2)}} Psionic Energy Die. You can use it to fuel any psionic power you have that use one. Some of your powers expend a Psionic Energy Die, you can’t use a power that requires a die when yours are all expended. Once per long rest you regain this expended Psionic Energy Die at the end of a Short Rest."

However, following that code, it results in a 1d13 at level 20 (admittedly, I have not tried it for the rest of the levels). It's for an effective feat-tree granting Psi-Warriors and Soul Knifes a bit more... jedi-y abilities via more psionic spells.

Sposta suggested posting here for help, so here I am.

Help me, Master Obi-wan Mairondil, you're my only hope.

You have an awful lot of parenthesis in that snippet.

Found this on that character sheet:

You have one Psionic Energy Die which is a d6, and it increases one die size when you reach certain levels: 5th (d8), 11th (d10), and 17th level (d12).

Snippet-Master Mairondil, I was working on some homebrew with IamSposta, and he came up with this, for the snippet.

"You have a <strong>1d</strong>{{6+((((characterlevel+1)/6)#rounddown)*2)}} Psionic Energy Die. You can use it to fuel any psionic power you have that use one. Some of your powers expend a Psionic Energy Die, you can’t use a power that requires a die when yours are all expended. Once per long rest you regain this expended Psionic Energy Die at the end of a Short Rest."

However, following that code, it results in a 1d13 at level 20 (admittedly, I have not tried it for the rest of the levels). It's for an effective feat-tree granting Psi-Warriors and Soul Knifes a bit more... jedi-y abilities via more psionic spells.

Sposta suggested posting here for help, so here I am.

Help me, Master Obi-wan Mairondil, you're my only hope.

You have an awful lot of parenthesis in that snippet.

Found this on that character sheet:

You have one Psionic Energy Die which is a d6, and it increases one die size when you reach certain levels: 5th (d8), 11th (d10), and 17th level (d12).

Thanks to Sposta and Mairondil for these, I’m not much of a snippet maker but seeing a new way math and things like GCF can be used is going to open (and blow) some young minds when I show some of this to the kids (and math teachers) at the middle school I sub for. :>~

Oh, don’t thank me, I just point people towards this thread. All the credit should go to, Mairondil, they’re the one who put this together. When I can’t figure out a snippet (and I’m good at math, just not algebra), I ask them for help.

Interesting comments in the Using Snippets pinned thread and I wanted to explore it further. Presented an interesting challenge was @Kitsune96 in comment #729. Basically they wanted this:

Since this was a racial feature, you couldn't just use {{scalevalue}} like in a subclass. We have to break this down into different parts:

number of dice+ "d" +die type+ {{modifier:cha}}. Luckily the challenge had a simple level progression to work with, just some change every 5 levels at 5, 10, and 15, so that made solving this a lot easier.I looked at the

number of dicefirst since it was incremental changes of a value by 1so it was the simpler of the two. With the incremental changes in number of dice happening at levels 10 and 15, we need to divide our character level by their greatest common factor (GCF), which happens to be 5. This gives us a new value to do stuff. From levels 1 through 4 that value is 0.something, levels 5-9 its 1.something, 10-14 its 2.something, 15-19 its 3.something, and at level 20 its 4. At this point we can apply the modifiers to give these new values a ceiling and a floor. Min:1 says nothing can be smaller than a 1 while max:3 says nothing can be higher than a 3. We'll also round down because whole numbers are sexy. This gives us this simple math:So now levels 1 through 9 will display a 1 in this snippet, levels 10-14 will display a 2, and levels 15 and above will display a 3.

I started looking at the second half of the challenge,

die type. It's on a similar incremental structure. Our GCF is still 5, so we'll still divide character level by that, but it's the value that isn't a regular pattern going from6, to10, to12. I was trying to figure out to make that work. I opened notepad and typed out 20 lines of level and desired result, then added a column for different calculation results. I probably should have just opened google sheets or something. I had tested little changes here and there in the structure. I used 9 custom actions, since I wanted to display the changes at 8 different levels, one to replicate each: 1, 4, 5, 9, 10, 14, 15, 19, and 20. I was getting close but couldn't quite wrap my head around it at work. Then I refreshed the forum and saw @Halfwing's attempt at it. After a copy paste glitch, he posted this:I pasted it in each of my 9 custom actions and changed characterlevel to the number I was testing in that action and it returned the correct value at each of the checkpoints. I'm obsessed over how this works.

He divides the level by the GCF and then round's down to get a new value. This gives levels 1 through 4 that value is 0, levels 5-9 its 1, 10-14 its 2, 15-19 its 3, and at level 20 its 4. Similar to where I was, just applying rounding now since we're not applying the min or max modifiers yet. These should be referred to as our initial values.

Then multiply that value by

4, so levels 1-4 the value is still 0, 5-9 the value is 4, 10-14 the value is 8, 15-19 the value is 12, and at level 20 the value is 16. This will give us our working values. Why did he multiply by4?The

die typechanges at levels 5 and 10 going from a6to a10to a12. For levels 1-4 our working value is 0. Simple enough:0 *

4+ 60 + 6

6So somewhere down the line we need to add 6 to all our values to get what we want to achieve at each character level. For levels 5 and up, it needs to be a

10or12.10- 6 =4. I mean, maybe. No? It's deeper than that and that deepness comes from the initial values. Looking at our initial values 1-4 is 0, 5-9 is 1, 10 and up is 2(or more). What we want to do is add to that +6 we're gonna tack on at the end to get10. For levels 5-9 we'll see why the4multiplier is necessary:1 *

4+ 64 + 6

10For levels 10 and up it's:

2(or more) *

4+ 68(or more) + 6

14(or more)

Since there's not another increment change above 10, we just need to throw a max in there. Since the last step is adding a 6 and our goal is

12, we can only have a max of. Mentioned before when we multiplied by64to calculate our working values: 10-14 the value is 8(max, 15-19 the value is 126)(max, and at level 20 the value is 166)(max. And:6)+ 6612So now we can solve for both parts and successfully snippeted

TFoutta this challenge resulting in:Maybe I'm obsessed, maybe I'm a nerd. YOU PLAY D&D, NERD! But I really loved not only trying to solve it but exploring the actual solution. I didn't want to crowd the Using Snippet thread with my inebriated ramblings. I just love you guys so much!!!!! Wait, wrong inebriation.

EDIT - added some RTF to show where the different values came from

How to: Replace DEX in your AC | Jump & Suffocation stats | Build a (Spell & class effect buff system | Wild Shape effect system) | Tool Proficiencies as Custom Skills | Spells at higher levels explained | Superior Fighting/Martial Adept Fix | Snippet Codes Explored - Subclasses | Snippet Math Theory | Homebrew Weapons ExplainedCheck out my: FEATS | MAGIC ITEMS | MONSTERS | SUBCLASSES Artificer Specialist: WeavebladeDndbeyond images not loading A PERMANENT WORKAROUND!!! (thank you Jay_Lane)Seeing a full breakdown of the math behind the code is always pleasing to me (I'm a math nerd myself). Although I figured out the main equation, it was a logarithmic equation, which DND Beyond does not have implementation at this time. I couldn't figure out a way to simplify the expression to make everything work. Happy to see that my question sparked a new thread! Thanks again for your help and @Halfwing's help :D

Inspired by Using snippet codes in your homebrew comment #757:

I knew it could be done with enough trial and error, but difficult. With the incremental changes coming at the odd levels of 8 and 13, it is not easily divisible. You can't use the greatest common factor (GCF) as they don't share any factors other than 1. The changes are continuous though going from a d4 to a d6, to a d8. Here's what I came up with:

We need to break this down a little bit. First, snippet codes don't fully implement PEDMAS as it's order of operations when calculating anything. So if you need to calculate something, it has to be really simple and able to be read left to right. We're starting with a 4 and adding to that:

Here we're taking characterlevel and dividing by 8, the max will be 1 (catching anything over level 16). Multiply that by 2. So levels 1-7, divided by 8 and rounded down to 0 times 2 is 0. Levels 8 and up, divided by 8 and be rounded down to 1 times 2, so 2.

So 4 plus 0 or 2. Then we add:

Here we divide by 13. No maximum is necessary here since you'd have to be level 26 to screw the snippet, which isn't possible. Round the result down and multiply by 2. So levels 1-12, divided by 13 and rounded down will be 0 times 2 which is 0. Levels 13 and up, divided by 13 will be 1 times 2, which is 2.

So 4 plus 0 or 2 plus 0 or 2 gives us a 4, a 6, or an 8 depending on what level we're at. We close up the snippet, throw the bells and whistles on it:

So it looks like there's a limited amount of PEDMAS implemented as inside the parenthesis

(classlevel/8)@max:1,rounddown*2is resolved with it's max and rounddown modifiers before multiplying by 2, but this is also being read left to right. All of this is calculated before the initial4+at the beginning of the snippet so there's some PEDMAS in there, but you cannot get complicated.Using a fully implemented PEDMAS,

((classlevel/8)@max:1,rounddown+(classlevel/13)@roundddown)*2+4should work, but it throws an error. As you can see we're getting complicated with nested parenthesis.~~I'm starting to think think that nested parenthesis aren't supported so that's going to make calculations lean on a left to right reading, with at least some PEDMAS to give a little priority to things.~~See comment #5 on my new theory regarding this.How to: Replace DEX in your AC | Jump & Suffocation stats | Build a (Spell & class effect buff system | Wild Shape effect system) | Tool Proficiencies as Custom Skills | Spells at higher levels explained | Superior Fighting/Martial Adept Fix | Snippet Codes Explored - Subclasses | Snippet Math Theory | Homebrew Weapons ExplainedCheck out my: FEATS | MAGIC ITEMS | MONSTERS | SUBCLASSES Artificer Specialist: WeavebladeDndbeyond images not loading A PERMANENT WORKAROUND!!! (thank you Jay_Lane)One thing I'm noticing when it comes to snippets displaying a dynamic type of die to use, ie. d4, d6, d8, etc, these more complicated snippets are starting (or ending) calculations with the default value. Comment #3 explores a snippet that adds 4 to some stuff. @Halfwing's portion of OP added a 6 to everything at the end. These are the lowest die types used in the snippet, a d4 and a d6 respectively. Getting the calculated value from a modifier, just needs to be reduced in such a way to add to that lowest die. Whether we're dividing by the GCF or any random level, we just want to get to the incremental change away from that first (or last) value.

How to: Replace DEX in your AC | Jump & Suffocation stats | Build a (Spell & class effect buff system | Wild Shape effect system) | Tool Proficiencies as Custom Skills | Spells at higher levels explained | Superior Fighting/Martial Adept Fix | Snippet Codes Explored - Subclasses | Snippet Math Theory | Homebrew Weapons ExplainedCheck out my: FEATS | MAGIC ITEMS | MONSTERS | SUBCLASSES Artificer Specialist: WeavebladeDndbeyond images not loading A PERMANENT WORKAROUND!!! (thank you Jay_Lane)Exploring another snippet I was very impressed with the first time I saw it. It's not mine, but I totally use it as a great way to calculate minutes you can hold breath in my Stats (Suffocation) feat and is in the Jump & Suffocation stats link in my signature (credit given to Glazia in that comment). They came up with this:

Well there goes my theory about nested parenthesis. Per the Player's Hand Book section:

So using PEDMAS, this totally makes sense. Add a 1 to to your CON. There is a minimum of 30 seconds, or 0.5 minutes, which is what the snippet produces if your CON modifier is -1 or lower. So we're adding 1 to our CON modifier and multiplying by 2 then dividing by 2, basically this allows us to turn any 1 into half, or 0.5.So if your CON modifier is 0, we're adding 1 inside the first parenthesis then multiplying by 2.

THISnumber we want a minimum of 1. So 0+1thentimes 2 gives a 2, but -1 CON modifier or anything more negative, gives a 0 or less, but our minimum is 1 so we end up with 1.Thenwe divide it all by 2. So that (0 CON mod + 1) * 2 /2 will give us the 1 we're looking for. Same for a +3 CON modifier. Same for a -3 CON modifier (giving us 0.5 minutes, which is correct).Why does a nested parenthesis work here, but not in the solution for comment #3? It might be related to how the snippet modifiers are implemented. This example has

@minand#unsignedoutside of the nested parenthesis, but my first try in comment #3 had the@maxand@rounddownon the inside some nested parenthesis before applying the next bit of math.Maybe the snippet modifiers can't be inside a set of parenthesis when applying later calculations. Knowing this could be useful when building snippets.The solution I have for #3 needed the @rounddown applied before multiplying by 2, because just for level 7, if we remove @rounddown we'll have 4 + 0.875+0.5384615.... which ends up being 4+1.4134615.... or 5.

somthingwhich is not the result I wanted. By breaking out the *2 portion on the divided by 8 and the *2 portion of the divided by 13 portion, we have to round down each to get the desired result.Check out my: FEATS | MAGIC ITEMS | MONSTERS | SUBCLASSES Artificer Specialist: WeavebladeDndbeyond images not loading A PERMANENT WORKAROUND!!! (thank you Jay_Lane)## Do anything with {{characterlevel}}

So a thought experiment led me to post in Using Snippet Codes in your Homebrew:

So let me explain what's going on here, let's break this down into it's different parts:

So the first part is calculating the number of damage dice. The last break in the iteration happens at level 13, but at level 7 we have an additional jump from 1 die to 2. But it goes back to 1 die at level 9. So we've got an irregular pattern here. Its probably easier to visualize broken down with each section on a new line:

The first thing we have is a 1 because we're starting with 1 damage die. The next iteration of change happens at level 7. At level 7 we change from 1 die to 2 dice, so we want to add 1 to our starting 1. We divide our character level by 7 and add that to our starting 1. Any characterlevel less than 7 is going to divide and rounddown to 0, so adding this for character levels under 7 is just going to add a 0, otherwise it'll add a 1. We put a max on here because levels 14 and up throw off the math and we're not ready for those levels yet.

The at level 9 we want to reduce that number of dice from 2 back down to a 1. We do the same trick of dividing our characterlevel by 9. Anything less than that rounded down is a 0. We stick a max on here too because level 18 throws off the math again. We subtract this from where we're at, again character levels less than 9 divide and rounddown to 0, subtracting nothing.

Finally we're going to bump the number of dice back up from 1 to 2. We do the same trick of dividing by the characterlevel the change is going to happen. Anything less adds 0, anything more adds a 1.

Basically what we're doing here is starting with an initial value and by dividing our current character level by our iteration points giving us a level switch to work with giving us a 0 or 1. we can add or subtract. Easy, right?

How about the second half of this? I'll go ahead and break it out on a new line for each section

Here we're looking to change the damage die(dice) in an irregular pattern too. The iteration is every 2 levels so there's really not a way to reduce that leaving us to have a calculation at every level change.

At level 1 we start with a d4, so a 4. Using the divide by iteration level and rounddown trick we learned earlier because we're going to be adding and subtracting things again. We need to throw some maximums on here because levels over 10 will cause math problems down the line if we don't put maximums on it. Like earlier if the characterlevel is less than that iteration it'll end up being rounded down to 0.

We are also multiplying each of these iterations. Since we're dividing and roundding down to a 0 or a 1, multiplying this by the change in value will give us a 0 or that change in value. For example, level 3 we're going from a d4 to a d6, so we want to take our level switch (a 0 or a 1) and multiply by 2. We're adding that. We do the same thing at level 5 to push us up to a d8.

Here's the irregular change, at level 7 we're going down to a d4 for that iteration so we want to subtract 4 from that 8. Then at level 9, we're going back up to a d10. So this level switch needs to multiply by 6 and add that to our 4. Bump up by 2 more at level 11.

At level 13, we want to subtract again going from a d12 to a d6. We get our level switch, multiply by 6 and subtract it. Then its just increasing by 2 at levels 15, 17, and 19.

So what did we learn? Level switches are a very useful tool. Basically we divide characterlevel by the iteration point we want, give it a maximum if that level iteration is 10 or under, and rounddown and you have a perfect YES or NO you can multiply by something. 0 multiplied by something will always be 0 so this really helps us adding or subtracting nothing for lower levels but still able to add or subtract something at

whatever level you choose.Check out my: FEATS | MAGIC ITEMS | MONSTERS | SUBCLASSES Artificer Specialist: WeavebladeDndbeyond images not loading A PERMANENT WORKAROUND!!! (thank you Jay_Lane)I just want you to know this thread came in very,

veryhandy the other day when I need help figuring out a snippet. Thank you!!“I don’t work here, I just live here.”My DM's Guild PublicationsMy YouTubeAdvice For New DMsThe Homebrewer's "How To" FAQWhat’s Your Backstory?My Homebrews: Spells, Monsters, Feats, Magic Items, Backgrounds, Subclasses, SpeciesCreating Epic Boons on DDBDDB Buyers' GuideHardcovers, DDB & YouContent TroubleshootingThat's my goal.

Now for my analysis of Halfwing's solution to that snippet challenge I posted the other day the other day in Using Snippet Codes in Your Homebrew:

My solution led to this thread's Do Anything with {{characterlevel}} comment. Basically using some simple level switches to add an subtract each iteration from level to level. Halfwing's solution simplifies that by grouping similar iteration changes together. Halfwing even posted a huge breakdown in order to visualize what needed to change. Let's breakdown the above snippet:

It's probably easier to visualize the first section as

(1+characterlevel/2)@roundup*2.The first group of iterations go from d4 to d6, to d8. Since each of these changes happens every other level (level 1, 3, & 5), we need

characterlevel/2and@roundupto group each pair of levels together (1 & 2, 3 & 4, 5 & 6). This will give us these values for levels 1 through 6: 1, 1, 2, 2, 3, 3. Getting these to the 4, 6, & 8 we want, we need to add 1 to each andthenmultiply by 2. By putting@roundupoutside of the parenthesis of adding that + 1, Halfwing is able to manipulate the order of operations to get the results we need for levels 1, 2, 3, 4, 5, & 6.Looking over Halfwing's breakdown, you can see this first section of the snippet gives an order of values for all the levels above 7 that we need the remaining sections to calculate. Level 7 we need a level switch to subtract 6 from the first section's value:

-(characterlevel/7)@rounddown,max:1*6. That level switch of (characterlevel/X)@rounddown*Y gives us that 0 or 1 value to tell us to subtract nothing if less than X level or subtract 1 times Y. Remember, if X is less than 10, we need to put a max on there because we don't want to subtract more than 6 once we get to 12 and higher. This section gives us the correct results for levels 7 and 8.Halfwing's visual shows us where the first two sections get us, but we have another change at level 9, going back up to a target of d10. Here we need to use a level switch to add 4 to our current value:

+(characterlevel/9)@rounddown,max:1*4. For all the same reasons above, this level switch gets us where we need to be on levels 9, 10, 11, & 12.The last section need's to subtract 8 from that current value after the 3rd section:

-(characterlevel/13)@rounddown*8. Here's another level switch used to subtract something only above a certain level. No need for a maximum value here since this returns a -0 if under level 13.Most of the heavy lifting on this is in the first section because the last 3 sections are just simple level switches to add or subtract something from that first section result. Breaking out the results in a table and color coding it like Halfwing did really did go a long way to visualize where we needed to go at each step. Manipulating the order of operations is the genius part because multiplying by 2 and adding 1 gives incorrect results but adding 1 and multiplying by 2 gives the right results.

Check out my: FEATS | MAGIC ITEMS | MONSTERS | SUBCLASSES Artificer Specialist: WeavebladeDndbeyond images not loading A PERMANENT WORKAROUND!!! (thank you Jay_Lane)I feel like I missed something. Where are the underlying principles of incremental change and how do we change the up or down.

I feel like it should be graphable. I can put (((x/7)2)+((x/9)2)+3)=y on a graph and get the the points I want

## My Brews:

Race: Tropical Dwaves Spells: Summon Spirits Rites of Mummification

Monster: Osprey Feat: Skill Mastery–Animal Handler (Provides DCs for training animals applicable to those with and without this feat)

The change up or down would be from leveling up, and/or ASI increases. Since snippet codes are built off of your character's level or modifiers, that's the variable we have to account for and use as our dynamic constant. The math behind the snippet variables needs to account for numbers from -single digits (probably) to +single digits (probably) AND/OR 1 through 20 and different incrementals (PB is 2, 3, 4, 5, 6, whereas levels are 1 through 20). Knowing what the limitations of x are is helpful in building your formula. As is knowing where whole numbers are useful and/or necessary..

Check out my: FEATS | MAGIC ITEMS | MONSTERS | SUBCLASSES Artificer Specialist: WeavebladeDndbeyond images not loading A PERMANENT WORKAROUND!!! (thank you Jay_Lane)Snippet-Master Mairondil, I was working on some homebrew with IamSposta, and he came up with this, for the snippet.

"You have a <strong>1d</strong>{{6+((((characterlevel+1)/6)#rounddown)*2)}} Psionic Energy Die. You can use it to fuel any psionic power you have that use one. Some of your powers expend a Psionic Energy Die, you can’t use a power that requires a die when yours are all expended. Once per long rest you regain this expended Psionic Energy Die at the end of a Short Rest."

However, following that code, it results in a 1d13 at level 20 (admittedly, I have not tried it for the rest of the levels). It's for an effective feat-tree granting Psi-Warriors and Soul Knifes a bit more... jedi-y abilities via more psionic spells.

https://www.dndbeyond.com/characters/131678842 - Here's the Homebrew test character I have them on if it assists in any way.

Sposta suggested posting here for help, so here I am.

Help me, Master Obi-wan Mairondil, you're my only hope.

Why is this not locked?

Oh well. On to the bookmarks bar it goes I guess.

Don't you just love platypuses/platypi/platypodes?

-Literally everyone ever

Proud member of the EVIL JEFF CULT! PRAISE JEFF!

Homebrew Races: HERE Homebrew Spells: HERE Homebrew Monsters: HERE

My trophy that I stole- I mean, won, in Last Comment Wins! (For realz this time):🏆

You have an awful lot of parenthesis in that snippet.

Found this on that character sheet:

Here's the snippet I would use:

Check out my: FEATS | MAGIC ITEMS | MONSTERS | SUBCLASSES Artificer Specialist: WeavebladeDndbeyond images not loading A PERMANENT WORKAROUND!!! (thank you Jay_Lane)All those parentheses are my fault. I knew you’d be the best person to help.

“I don’t work here, I just live here.”My DM's Guild PublicationsMy YouTubeAdvice For New DMsThe Homebrewer's "How To" FAQWhat’s Your Backstory?My Homebrews: Spells, Monsters, Feats, Magic Items, Backgrounds, Subclasses, SpeciesCreating Epic Boons on DDBDDB Buyers' GuideHardcovers, DDB & YouContent TroubleshootingThey really aught to pin it.

“I don’t work here, I just live here.”My DM's Guild PublicationsMy YouTubeAdvice For New DMsThe Homebrewer's "How To" FAQWhat’s Your Backstory?My Homebrews: Spells, Monsters, Feats, Magic Items, Backgrounds, Subclasses, SpeciesCreating Epic Boons on DDBDDB Buyers' GuideHardcovers, DDB & YouContent TroubleshootingThis worked like a charm, thank you for your assistance! (And also thanks Sposta, for sending me toward you)

Of course. Nobody better I know of with snippets than

Mairondil, they’re, like, a guru.“I don’t work here, I just live here.”My DM's Guild PublicationsMy YouTubeAdvice For New DMsThe Homebrewer's "How To" FAQWhat’s Your Backstory?My Homebrews: Spells, Monsters, Feats, Magic Items, Backgrounds, Subclasses, SpeciesCreating Epic Boons on DDBDDB Buyers' GuideHardcovers, DDB & YouContent TroubleshootingThanks to Sposta and Mairondil for these, I’m not much of a snippet maker but seeing a new way math and things like GCF can be used is going to open (and blow) some young minds when I show some of this to the kids (and math teachers) at the middle school I sub for. :>~

Wisea$$ DM and Player since 1979.

Oh, don’t thank me, I just point people towards this thread. All the credit should go to,

Mairondil, they’re the one who put this together. When I can’t figure out a snippet (and I’m good at math, just not algebra), I ask them for help.“I don’t work here, I just live here.”My DM's Guild PublicationsMy YouTubeAdvice For New DMsThe Homebrewer's "How To" FAQWhat’s Your Backstory?My Homebrews: Spells, Monsters, Feats, Magic Items, Backgrounds, Subclasses, SpeciesCreating Epic Boons on DDBDDB Buyers' GuideHardcovers, DDB & YouContent TroubleshootingYeah but you I follow which led me to the thread so you get some thanks too.

Wisea$$ DM and Player since 1979.