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

Macro to roll a Rollable Table

I would like a macro that rolls a d20 and if the result is a 1, it will then roll from a rollable table. If the result is anything but a 1, then nothing.
1696547354

Edited 1696547654
Andrew R.
Pro
Sheet Author
That sounds like a conditional, which the Roll20 macro language doesn’t support.  You can do that easily with ScriptCards, for example. I’ll post an example later if you like.  You can also do it with the Metascripts Toolbox, but I can’t do an example for that. 
1696552736
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hi Charles! This is an old trick.  Create your rollable table. Name the table "1" When you use this macro: [[1t[[[1d20]]]]] ...if a 1 is the result, it will roll on the table named 1. Otherwise it will ignore the roll.
1696593985
Andrew R.
Pro
Sheet Author
Neat!
What's the rest of the macro or is it just that? I wanna say I'm pretty savvy when it comes to this, but in reality I'm totally lost. 
1696597116

Edited 1696597141
Andrew R.
Pro
Sheet Author
It rolls a D20 and uses the result as the name of a rollable table. Since you have a rollable table called “1” and no others, only a result of 1 will get the rollable table result.  It’s a trick of the Roll20 macro language parser. 
I understand what it does, but how do I use it in a macro? Add new macro, give it a name, paste this text in. Add a new rollable table, name it 1, add the options. Save all and click the macro and nothing happens, click it a lot and nothing?
1696601526

Edited 1696601600
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Change the 1d20 to a 1d2 and you should see results about 50% of the time. Right now, given the parameters, there will only be output 5% of the time (1 on a d20). The explanation you gave was " If the result is anything but a 1, then nothing." There is a trick to getting that number to display twice in the same macro , but in this case it is swallowed by the table roll and inaccessible. Maybe someone like Rainbow Encoder, the Wizard of Macros knows a trick to pull that number out, but I can't get it to display. Another option (a bit more work) would be to put the whole roll into a table, including the numbers 2-20. This would require weighting the table properly, but would report the number every time. You would give every result on your sub-table a weight of 1, and each of the numbers 2-20 a weight equal to the total number of items in your sub table: Weight: Item name 1:Option A 1:Option B 1:OptionC 1:OptionD 4:2 4:3 4:4 ... Finally, since you are a Pro user, you could look into the Recursive Tables mod script. This allows you to refer to a table from within another table. you would still need a table of the 1-20 rolls, but you wouldn't have to mess with weighting a bunch of entries. You can find an explanation of the script here .
1696601788
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Fourth option: If you don't care what the number was, but you just want confirmation that the roll occurred, change your macro to something like: The result was either a roll of 2-20, or: [[1t[[[1d20]]]]]
1696602646

Edited 1696602856
That's a lot of info! Thanks, got a lot to read. But I think I figured out what I was trying to do. Took a lot of googling but this is what I ended up with. &amp;{template:traits} {{name=Wild Surge!}} {{source=Roll a d20 immediately after you cast a sorcerer spell of 1st level or higher. If you roll a 1, a Wild Magic Surge creates a magical effect.}} {{description=[[ [[1d20=1]]t[Wild-Magic] ]] [Magic Surge]( <a href="https://i.pinimg.com/originals/b7/31/c4/b731c4f8ecd4cbfb4e38cfe3bd38905b.gif" rel="nofollow">https://i.pinimg.com/originals/b7/31/c4/b731c4f8ecd4cbfb4e38cfe3bd38905b.gif</a> )}}
1696614855
timmaugh
Forum Champion
API Scripter
Here is what that would look like if you wanted to implement the MetaScriptToolbox: !&amp;{template:traits} {{name=Wild Surge!}} {{source=Roll a d20 immediately after you cast a sorcerer spell of 1st level or higher. If you roll a 1, a Wild Magic Surge creates a magical effect.}} {{description={&amp;if [[1d20]] = 1}[[1t[Wild-Magic]]] [Magic Surge ](<a href="https://i.pinimg.com/originals/b7/31/c4/b731c4f8ecd4cbfb4e38cfe3bd38905b.gif" rel="nofollow">https://i.pinimg.com/originals/b7/31/c4/b731c4f8ecd4cbfb4e38cfe3bd38905b.gif</a>) {&amp;else}There was no surge. The roll was $[[0]]{&amp;end}}}{&amp;simple} That uses APILogic to handle the conditional, and ZeroFrame to output the template to chat (both are included in the MetaScriptToolbox). The chief difference between this and the Roll20 parsing trick Keith demonstrated is that this version would allow you to re-reference your initial roll to, for instance, report the actual value.