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

How to roll on a table a random number of times

I have a macro that prompts for the number of times to roll on a table. !note-text {{ *********************************************************************************** Type=?{Type of Location|Residential,Residential|Commerical,Commerical|Industrial,Industrial|Medical,Medical|Agricultural,Agricultural|Military, Military} Ammunition=[[?{How Many Ammo|1}t[Random-Ammunition]]] Armor=[[?{How Many Armor|1}t[Random-Armor]]] Location= [[1t[Hit-Locations]]] Beverages=[[?{How Many Beverages|1}t[Random-Beverages]]] Chems=[[?{How Many Chems|1}t[Random-Chems]]] Clothing=[[?{How Many Clothing|1}t[Random-Clothing]]] Food=[[?{How Many Food|1}t[Random-Food]]] Publications=[[?{How Many Publications|1}t[Random-Publication]]] Weapons=[[?{How Many Weapons|1}t[Random-Weapons]]] Encounter=[[1t[Room-Encounters]]] }} I want to replace the How Many prompts with a static 1d4-1. Something like: Ammunition=[[1d4-1t[Random-Ammunition]]]) How do I go about this?
1716311674
timmaugh
Forum Champion
API Scripter
[[[[1d4-1]]t[Random-Ammunition]]] Be aware that this will return a "0" if you roll a 1... because then you'll roll 0 times against the table... but otherwise this will work.
OK, here's the current macro. note-text {{ *********************************************************************************** Type=?{Type of Location|Residential,Residential|Commerical,Commerical|Industrial,Industrial|Medical,Medical|Agricultural,Agricultural|Military, Military} Ammunition=[[[[1d4-1]]t[Random-Ammunition]]] Armor=[[[[1d4-1]]t[Random-Armor]]] Location=[[1t[Hit-Locations]]] Beverages=[[[[1d4-1]]t[Random-Beverages]]] Chems=[[[[1d4-1]]t[Random-Chems]]] Clothing=[[[[1d4-1]]t[Random-Clothing]]] Food=[[[[1d4-1]]t[Random-Food]]] Publications=[[[[1d4-1]]t[Random-Publications]]] Weapons=[[[[1d4-1]]t[Random-Weapons]]] Encounter=[[1t[Room-Encounters]]] }} However, now nothing is being produced. If I run a line in the chat window, it displays one of the results, but hovering over the result shows additional results. Suggestions?
1716318127
timmaugh
Forum Champion
API Scripter
If you want to display all of the results at once, I'm currently working on adding that functionality to the MetaScriptToolbox... So in a week or so, I should have something for you. =D
1716372865

Edited 1716373019
David M.
Pro
API Scripter
In your first example, you start with "!note-text", but your second example is missing the exclamation, i.e. "note-text". Is this supposed to be input to a mod script? Aside from that, a Scriptcard macro would work for this. Here's a dummy example using existing rollable tables in my test game. You can just change the title/query and add as many function call lines as you want using -->RollOnTable|Header;TableName When you call the function, it rolls 1d4-1 and then loops through each table roll with chat output.  !script {{ --#title|Potion Generator --+Potion Color|?{Color of Potion|Red|Orange|Yellow|Green|Blue|Indigo|Violet} -->RollOnTable|Effect;PotionEffect -->RollOnTable|SideEffect;PotionSideEffect --X| End Macro --:FUNCTIONS| --:RollOnTable| accepts header and tableName as parameters --=roll|1d4-1 --?[$roll] -eq 0|[ --+[%1%]|None --]|[ --%i|1;[$roll.Raw];1 --=tableRoll|[T#[%2%]] --+[%1%] [&i]|[$tableRoll.tableEntryText] --%| --]| --<| }}
That works great, David. Now, how can I write the output to a handout?
Current version: !script {{   --#title|Fallout Location Generator   --+Type|?{Type of Location|Residential,Residential|Commerical,Commerical|Industrial,Industrial|Medical,Medical|Agricultural,Agricultural|Military, Military}   -->RollOnTable|Ammunition;Random-Ammunition   -->RollOnTable|Armor;Random-Armor   -->RollOnTable|Beverage;Random-Beverages   -->RollOnTable|Chem;Random-Chems   -->RollOnTable|Clothing;Random-Clothing   -->RollOnTable|Food;Random-Food   -->RollOnTable|Weapons;Random-Weapons   -->RollOnTable|Publication;Random-Publication       --X| End Macro   --:FUNCTIONS|   --:RollOnTable| accepts header and tableName as parameters     --=roll|1d4-1       --?[$roll] -eq 0|[           --+[%1%]|None       --]|[           --%i|1;[$roll.Raw];1               --=tableRoll|[T#[%2%]]               --+[%1%] [&i]|[$tableRoll.tableEntryText]           --%|       --]|   --<| }}
1716423434
David M.
Pro
API Scripter
Hmm, I'm not really sure how to write it to a new handout programmatically using SC. SC has a method to modify an object (including handouts), but you have to know the object id ahead of time (maybe metascripts might be able to help you here with a lookup using the name - probably a Fetch construction?  Tim?). I don't think SC can create handouts for you. But, with an object id you could write to a default handout and cut/paste into a new one. Not ideal, though. If that is your ultimate goal, then maybe Tim's pending metascript update is the better way to go about this if it's something you do frequently.