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
This post has been closed. You can still view previous posts, but you can't post any new replies.

If/Then Capability (albeit a very limited one) using rollable tables

1468189860

Edited 1468189969
Matt
Plus
I've seen a lot of clamor for if/then capability in roll20 (outside of API and custom Roll Template things), and there is a workaround for certain situations you would want if/then functionality in your code using rollable tables that I don't often see discussed (probably because it is so situationally useful) and I figured I would post about in case it fit what someone needed. This workaround comes from roll20's order of operations , namely the fact that rollable tables are considered "rolls" and are therefore evaluated after Roll Queries! 1. What is the workaround? So here's the gist of it: you embed a roll query inside the name of a roll template that you are rolling, then have a series of rollable tables with the values you want made in your rollable tables tab. Here's what that would look like: /me checks the value of an item of Level ?{Level|1}: [[ 1t[ItemLvl?{Level|1}] ]] gp. You would then have a series of rollable tables made up with single entries. For instance in 4e, ItemLvl1 would be a table with an entry of 360, ItemLvl2 would be a table with an entry of 520, ItemLvl3 would be a table with an entry of 680, and so on. Thus, in this sort of sense, you use a Roll query as an "If" to find the right table, which then contains an entry that is your "then." Because the Roll Query is evaluated before the table is rolled, you don't get the usual problem like you would if you tried to make an attribute @{ItemLvl1}, as it would look for an attribute named "@{ItemLvl?{Level", attempting to evaluate the attribute before the roll query makes the attribute meaningful (see order of ops link above). 2. What is it useful for? It is primarily useful for numeric things that are non-linear, such as a loot generator. For one of my 4e campaigns, I have a loot generator that looks like the following: /desc The party divides up the loot! /w gm Gold for Level ?{Level|1}: [[floor(((?{Experience|0}/(1t[ExpL?{Level|1}]))*(0.75+0.1*(4d5/4)))*1t[ItemL?{Level|1}]) ]] gp. In this macro, Experience gained for each PC and the Level of each PC is asked for using a Roll Query and then the resulting input is used to determine 1. How much experience they gained relative to how much they need to reach the next level (found in the tables ExpL1 through ExpL30) and 2. How much gold an item of the player's level is worth (found in ItemL1 through ItemL30) so that their reward is properly scaled to them. Because item values in 4e increase geometrically/multiplicatively rather than arithmatically, and the Experience from level to level also jumps around (and roll20 does not have exponent support), using rollable tables (even ones that only have one entry) as if/then statements allows proper scaling to be implemented. You could also add randomization into your loot generator by having several entries in the rollable table, e.g. instead of just having "1000" in ItemL5, you could add in entries for 900 or 1100 as well. (You may notice that I don't do that above, instead using die rolls to add "luck" to the loot). Note: While it is open to more than just Mentor/Pro subscribers (unlike API and custom roll templates), it does require you to be a GM in the campaign in order to make and edit the rollable tables. 3. What can it NOT do? The short answer is " LOTS. " This little workaround is really only good for things that have numeric outputs, as words in rollable table outputs are done as Strings which cannot be evaluated. (To see what I mean, try making a rollable table called "test" that has "d20" as one of the entries, then try to do [[ [[ 1t[test] ]] ]]. It will not evaluate the d20, but rather show "d20" as the output text, then turn that into a "0"). I also cannot see a way for this to be used to instantly show crit damage when nat 20s are rolled (as roll templates can). Nor will it determine if an attack roll is higher than a defense and instantly subtract HP. All it really can do as far as I can tell is output the correct number(s) in response to your inputs. I would welcome thoughts on other ways this could be useful, but I hope it is helpful in its own limited way to some other folks on roll20. Cheers!
1468195942

Edited 1468196263
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Matt W. said: 3. What can it NOT do? The short answer is " LOTS. " This little workaround is really only good for things that have numeric outputs, as words in rollable table outputs are done as Strings which cannot be evaluated. (To see what I mean, try making a rollable table called "test" that has "d20" as one of the entries, then try to do [[ [[ 1t[test] ]] ]]. It will not evaluate the d20, but rather show "d20" as the output text, then turn that into a "0"). I also cannot see a way for this to be used to instantly show crit damage when nat 20s are rolled (as roll templates can). Nor will it determine if an attack roll is higher than a defense and instantly subtract HP. All it really can do as far as I can tell is output the correct number(s) in response to your inputs. I would welcome thoughts on other ways this could be useful, but I hope it is helpful in its own limited way to some other folks on roll20. Cheers! While "d20" is interpreted as a string, if I remember correctly if the result of a rollable table is just a number it can be used for further operations, so [[1d[[1t[?{DiceSize}] ]]]] or [[[[1t[?{DieNum)] ]]d20]] should work. Of course you don't really need to do this for that anyway (as you could just use the roll query itself). 1. What is the workaround?So here's the gist of it: you embed a roll query inside the name of a roll template that you are rolling, then have a series of rollable tables with the values you want made in your rollable tables tab. Here's what that would look like: /me checks the value of an item of Level ?{Level|1}: [[ 1t[ItemLvl?{Level|1}] ]] gp. While this is certainly interesting, I'm not sure why it would be the preferred way to do it as it requires setting up rollable tables, which only the GM can do. I can't really see any benefit to doing this as opposed to ?{Level|1,valueforlvl1|2,valueforlvl2|...|n,valueforlvln}, although I could just be not being imaginative enough.
1468202339

Edited 1468224861
Matt
Plus
Scott C. said: While "d20" is interpreted as a string, if I remember correctly if the result of a rollable table is just a number it can be used for further operations, so [[1d[[1t[?{DiceSize}] ]]]] or [[[[1t[?{DieNum)] ]]d20]] should work. Of course you don't really need to do this for that anyway (as you could just use the roll query itself). Yes. If you look at the main example I give in section 2, it shows me doing all sorts of multiplication and stuff like that to the resulting numbers. That's why I recommend using it only for numeric values. Including letters makes it stringy. I do in fact specify " words in rollable table outputs are done as strings that cannot be evaluated." Scott C. said: While this is certainly interesting, I'm not sure why it would be the preferred way to do it as it requires setting up rollable tables, which only the GM can do. I can't really see any benefit to doing this as opposed to ?{Level|1,valueforlvl1|2,valueforlvl2|...|n,valueforlvln}, although I could just be not being imaginative enough. tl;dr: The advantage over the dropdown menu is that if you're doing a 4e game that goes lvl 1 to lvl 30, you do not need to scroll through a menu with 30 options. You can just type in the number you want and presto! It's a fixed time cost of setting up the rollable tables rather than a variable time cost of looking through a giant drop-down, so I went with the fixed. Furthermore, if you did it with dropdowns, you would need to have it ask for the level twice, and do so with different prompts; asking for "Level" for both XP and gold would cause the "valueforlvl1" for the XP (e.g. 1000) for level 1 to be used for both the XP and the Gold for lvl 1 (should be 360, but will be overwritten by the first prompt as 1000), which is a rather unfortunate bug of the dropdown system. Again, minor difference, but this setup, while messy to do, once set up is good to go forever, and only prompts you once for XP and once for level, rather than giving you three prompts, including two duplicates. Additionally, I made this generator before the dropdowns were a thing, which is the main reason I didn't use them! :-D
1468204594

Edited 1468204837
Silvyre
Forum Champion
Matt W. said: Additionally, I made this generator before the dropdowns were a thing, which is the main reason I didn't use them! :-D Definitely a very clever solution to that issue! I sometimes suggest something similar with Rollable Tables for non-API conditional evaluation . Matt W. said: The advantage over the dropdown menu is that if you're doing a 4e game that goes lvl 1 to lvl 30, you do not need to scroll through a menu with 30 options. You can just type in the number you want and presto! Actually, you can navigate through a dropdown menu with your keyboard. You should be able to do the same thing, here. I really like using arrow keys plus the enter key to navigate through and submit Roll Queries with dropdown menus. Matt W. said: /desc The party divides up the loot! /w gm Gold for Level ?{Level|1}: [[floor(((?{Experience|0}/(1t[ExpL?{Level|1}]))*(0.75+0.1*(4d5/4)))*1t[ItemL?{Level|1}]) ]] gp. [...] Furthermore, if you did it with dropdowns, you would need to have it ask for the level twice, and do so with different prompts; asking for "Level" for both XP and gold would cause the "valueforlvl1" for the XP (e.g. 1000) for level 1 to be used for both the XP and the Gold for lvl 1 This is really where this strategy shines, and what makes it a great alternative to Roll Queries. In case you're curious, here's the Advanced Roll Query equivalent: /desc The party divides up the loot! /w gm Gold for Level ?{Level| 1, 1: [[ floor(?{Experience|0} / 1000 * (0.75 + 0.1 * 4d5 / 4) * 360) ]] | 2, 2: [[ floor(?{Experience|0} / 2250 * (0.75 + 0.1 * 4d5 / 4) * 520) ]] | etc., etc. } gp. Alternatively, without Advanced stuff: /desc The party divides up the loot! /w gm [[ floor(?{Experience|0} * (0.75 + 0.1 * 4d5 / 4) / ?{Level| 1, 1000 * 360) ]] gp. (Level 1) | 2, 2250 * 520) ]] gp. (Level 2) | etc., etc. }
1468206656

Edited 1468224923
Matt
Plus
Silvyre said: Matt W. said: The advantage over the dropdown menu is that if you're doing a 4e game that goes lvl 1 to lvl 30, you do not need to scroll through a menu with 30 options. You can just type in the number you want and presto! Actually, you can navigate through a dropdown menu with your keyboard. You should be able to do the same thing, here. I really like using arrow keys plus the enter key to navigate through and submit Roll Queries with dropdown menus. Haha yeah but again, pressing the down arrow 15 times is not exactly a party either! EDIT: just realized you meant typing the number into the dropdown and hitting enter. Sure, that would work too. Good suggestion about the nested drop-downs but honestly coding the drop-down itself tends to be cumbersome, so I think in all my macros I've ever made (easily in the thousands) I have nested drop-downs a grand total of twice, just because it's often not worth it.