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

[Script] RecursiveTables -- Expands Inline Rolls in Rollable Table Results

1478889626
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The Aaron said: Thanks, happy to help!  =D So the biggest problem there is the @{selected} part, but it's not impossible.  I need to revisit this script (Scott made some great changes to it that I need to release!), I'll see what I can come up with.  =D Heh, you've been busy :)
How do I get a table selection to roll  on another table. For instance I have a Table with Races and if someone lands on Dragonborn then I want it to roll the color of Dragonborn, which is another table.
1478892191
The Aaron
Pro
API Scripter
You just use the inline roll syntax.  Assuming your tables are Race and DragonColor, you might have an entry that looks like: Dragonborn, [[1t[DragonColor] ]]
1478892415

Edited 1478892911
Ahh, the elusive comma is what was killing me. I tried so many different ways. Edit: Some reason this isn't working for me.
1478892894
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The comma isn't what you were missing. Dragonborn [[1t[DragonColor] ]] would work just fine as well. The important part is to have the table call in an inline roll.
This is what is popping for me.
1478893805

Edited 1478893820
The Aaron
Pro
API Scripter
Right.  You'd have to use something like !rt [[1t[Race] ]] To get Recursive Tables to parse this recursively.
What do I have to do here to get it to come out right?
1478894819
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You need to call the script. Currently the script won't do both slash commands and roll templates. Change your macro to be: !rt /w gm [[1t[Race] ]] [[1t[Classes] ]] | [[1t[Classes] ]] .. or !rt &{template:default} {{[[1t[Race] ]]}} ...
That did it, awesome thank you guys. You are so awesome.
Next question how do I get the macro to ask me what level I want the Character to be, instead of a static number?
1478895542
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
That will be  roll queries : ?{level|1}
1478895622
The Aaron
Pro
API Scripter
just replace the static number with something like: ?{Level|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20}
1478895679

Edited 1478896403
So would it be {{Level[[?{level|1}]]}} ?? Edit: Thank you again it works as intended you guys make it great to ask questions.
I was wondering if anyone here would know how to handle <br> when importing tables into r20, using !import-table-item.  I can add them in manually but when I try to use the importer it just comments them out.  Even if I try to escape them as <%%60%%>br<%%62%%> it just uploads that literally.
1481984868
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I'd suggest trying <%0A> or<%0D> for line feed or carriage return respectively, but I have no idea if tableexport is programmed for those.
That didn't Work, but looked at the code, and noticed that the <%% %%>> for [[ was escaped; I just copied that for the < and > symbols and it seems to work.  Honestly, I think it would be better if I could find a way to have a more readable.  Such as automatically converting <br> into <%%60%%>br<%%62%%> without the weird symbolism.  But that's currently beyond my pay grade. Will continue to tinker, but honestly, if I have to alter the code to get it to work, there isn't much point to creating an import/export file, since I'd be the only one able to use it.  Although, honestly I can see this as perhaps being useful enough, maybe I can convince our friendly Lord Scriptomancer to add those escapes in, if they wont break other things.  Come to think of it, the new code would allow for limited html... perhaps, honestly don't know how html interacts with chat.
1482004576
The Aaron
Pro
API Scripter
Hi all, sorry for the delay, babies and such.  I'll take a look at the line breaks in tables.  Can you give me a very short example of what you would like to import so I can test with it?  One row should be sufficient.
As an example of an import table I'll use an incomplete table I've been working on for ultimate campaign.  Part of the limitation of roll tables in roll20, is the lack of multi level support.  That is having an entire row of a table fixed.  So you cant have a label for each seperate repeating entry.  I've tried to fake this by entering line brakes '<BR>'.  This works as long as I enter the table manually, in roll20, but when I try to use the importer with this code, or similar. the html entities are entirely stripped out. !import-table --rEn-Hazards --hide !import-table-item --rEn-Hazards --**bad weather**<br>a description of what this does goes here. !import-table-item --rEn-Hazards --**blight**<br>a description of what this does goes here. !import-table-item --rEn-Hazards --**deadly gas in the desert or marsh**<br>a description of what this does goes here. !import-table-item --rEn-Hazards --**a dust devil in the desert, hills or plains**<br>a description of what this does goes here. !import-table-item --rEn-Hazards --**a grass fire in the hills or plains**<br>a description of what this does goes here. !import-table-item --rEn-Hazards --**tremors**<br>a description of what this does goes here. Removing whitespace so its jsut one long continuous line of text.  I have managed to edit the code for table import script by adding in escape support for '<' and '>' and it seems to work.  But it makes the code almost unreadable.  Much in the same way you have to escape  '[' and ']'. var version  = '0.2.3',         lastUpdate = 1453209012,         tableCache = {},         escapes = {             '['   : '<%%91%%>',             ']'   : '<%%93%%>',             '<'   : '<%%60%%>', // <-- Added to allow for '<'             '>'   : '<%%62%%>', // <-- Added to allow for '>'             '--' : '<%%-%%>',             ' --' : '[TABLEEXPORT:ESCAPE]'         }, It works, I have no idea what, if any sort of conflicts it creates, but honestly if there were some way to allow direct use of '<br>' or any other 'clean' version of a newline, line feed or carriage return such as '\n\ or some variant to keep the code more readable that would be even better.
1482038950
The Aaron
Pro
API Scripter
That shouldn't cause any conflicts. Probably the <br> was getting eaten by the chat system  edited reaching the API. I'll do some testing tomorrow and see. 
1483592299

Edited 1483592403
Hey Aaron, Finally got around to actually using this. Thanks for making it! Having a problem with it though. Everytime I use it to make a roll it always sends a double message to chat (see pics). Do you know why it's doing this and if so is there a fix for it?
1483592599
The Aaron
Pro
API Scripter
What command are you sending?
The Aaron said: What command are you sending? !rt /w gm Group encounters [[ 1t[Episode-1-Encounters] ]]!
1483630665
The Aaron
Pro
API Scripter
Hmm.. that's weird.  I might have to explore that in your game, if that's a possibility.  Can you PM me a link and GM me?
1483633217
Ziechael
Forum Champion
Sheet Author
API Scripter
For double output always check to make sure you don't have duplicate scripts installed <-- voice of bitter experience
1483633429
The Aaron
Pro
API Scripter
That shouldn't be possible with my scripts, but it never hurts to check. =D More likely would be a second copy of the API running for your game, which I've seen happen a few times.
1483636447
The Aaron
Pro
API Scripter
The Aaron said: That shouldn't be possible with my scripts, but it never hurts to check. =D More likely would be a second copy of the API running for your game, which I've seen happen a few times. Come to think of it, it might register multiple event handlers if you had the script in there twice... something to fix in my pattern!!!
1483639652
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The Aaron said: The Aaron said: That shouldn't be possible with my scripts, but it never hurts to check. =D More likely would be a second copy of the API running for your game, which I've seen happen a few times. Come to think of it, it might register multiple event handlers if you had the script in there twice... something to fix in my pattern!!! How would you prevent that?
1483639810
The Aaron
Pro
API Scripter
Either a flag inside the closure that tells it that initialization has already happened (so skip operations in CheckInstall() and RegisterEventHandlers()), or redefining those functions to _.noop as the last step of their execution (which is harder than it sounds).
The Aaron said: That shouldn't be possible with my scripts, but it never hurts to check. =D More likely would be a second copy of the API running for your game, which I've seen happen a few times. That's what it was. I had 2 of the scripts running but I must have changed the name on it when I first installed it. <---NooB :)
1483668240
The Aaron
Pro
API Scripter
Great!
Hey Aaron, the commands working after !rt doesn't seem to be working for me. I'm using: !rt /w gm &{template:default} {{name=Random Encounters (Page 29)}} {{Encounter?=[[1t[Encounter-Chance]]]}} {{Day Encounter=[[ 1t[Daytime-Random-Encounters] ]]}} {{Night Encounter=[[1t[Nighttime-Random-Encounters]]]}} To roll up a random encounter by calling a few macros and sticking them into a template, but the /w gm aspect isn't working. It just says it publicly. The macro works with or without the /w gm, so it's basically being completely ignored. 
1484847116

Edited 1484847136
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Currently the script doesn't respect slash commands and roll templates simultaneously (templates currently override slash commands). It's a fix that is put in for the update that is currently being worked on.
1484848975
The Aaron
Pro
API Scripter
ug!  I must review that and push it out.. =(  Too much to do...
1484851397
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
heh, it's ok, you can just tell me that it's horrible and needs to be totally reworked ;)
Got it. I'll pull them out of the template for the time being then. Thanks.
1485503096

Edited 1485511359
Elena S.
Sheet Author
Getting some kind of weird results when I roll the same table multiple times. Trying to set up a macro to generate random gems. Here's a sample of my how my table entries are set up. I have a basic weighted table that determines the value category, several sub-tables with different types of stones (Ornamental, Fancy, etc.), and a second weighted sub-table with possible modfiers to the value of the gems ranging from 0.5 to 2.0 (GemValueMod). !rt /w gm [[ ?{How many Gems have been found?|1}t[GEM-CLASS] ]] [[ 1t[Ornamental] ]] ( [[ 200 * [[ 1t[GemValueMod] ]] ]] SP ) When I have it roll the table just once it works perfectly and returns something like this. (From Elena-DM (GM)): Lapis Lazuli (220 SP) But when I ask it to roll multiple times I get weird results such as: (From Elena-DM (GM)): Blue Quartz (0 SP), Alexandrite (20 GP), 0 (20 GP), 0 (0 GP) (From Elena-DM (GM)): Azurite (200 SP), Turquoise (0 SP) Is this a known quirk, or did I miss something somewhere? Oh, and the whisper-able templates with !rt would be spectacular!
1485525053
The Aaron
Pro
API Scripter
That is a known issue. Scott graciously fixed it for me and I've been a bum about rolling those changes out. I'll prioritize that for next. 
1485526822
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Elena, I don't know what it is, but you sure know how to light a fire under Aaron :) Also, he says graciously fixed it for him, when he means, just helped out because Aaron was and is crazy busy.
1485527810
The Aaron
Pro
API Scripter
Right question, right time. :)
Scott C. said: Elena, I don't know what it is, but you sure know how to light a fire under Aaron :) Also, he says graciously fixed it for him, when he means, just helped out because Aaron was and is crazy busy. It's my irresistable charm of course. ;)
1485545424

Edited 1485545473
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The Aaron said: That is a known issue. Scott graciously fixed it for me and I've been a bum about rolling those changes out. I'll prioritize that for next.  Also, might be more correct to say, I hope I fixed it, since I was never able to replicate the issue myself, so we're just assuming we fixed it based on what Aaron thought the problem was. Elena S. said: Scott C. said: Elena, I don't know what it is, but you sure know how to light a fire under Aaron :) Also, he says graciously fixed it for him, when he means, just helped out because Aaron was and is crazy busy. It's my irresistable charm of course. ;) Of course ;)
1485545542
The Aaron
Pro
API Scripter
Basically, I fall in the trap easily of "that would be easy..."
Hey, if how quickly you got all the stuff I've been asking about over the last week created or updated is an indication.... For you, most of it has been pretty easy. And/or you found someone to kick the right snippets down pretty fast!
1485562126
The Aaron
Pro
API Scripter
Not too bad. :)
Okay, I'm just revisiting this a bit since I figured something out with how I had some of the math formula set up in one of my tables where I'm getting the unexpected behavior. I switched the formula around. I was multiplying by a decimal (Float) and changed it so it's multiplying by a whole number and then dividing by 10 to get the gem value adjustments. After doing that It's working great for that portion of the recursive table function. I stopped getting 0's in the gem value part of it, regardless of how many times I tell it to roll the base table. But I'm still getting 0 values for the gem names whenever I roll the table more than twice. It was kind of throwing me because I'm only getting the unexpected behavior with that one table. I have other tables with multiple nested tables and many of them include mathematical functions in the rolls. None of them are giving me this sort of behavior. Does the value modifier formula with a divisor or floating-point multiplier cause that unexpected behavior? I went through and built a set of separate tables with specific values and everything is working just fine for both the values and for the names now. I don't understand why it behaves like this but I've got a workaround so I guess that particular quirk doesn't really matter anymore.
1486869371
The Aaron
Pro
API Scripter
That particular unexplained behavior is what prompted Scott to make modifications to it. I'll try and look at it this week. Scott deserves better than I've given him on this one. (Sorry Scott!)
1486869979
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
hah, not like you don't have a ton going on ;).
So, I'm also getting this strange zero value. I've done some tweaking with my table to try and narrow it down so maybe it will help. This is the entry that is causing the issue: [[1t[TreasureHoardCoins04]]], [[[[2d6]]t[Gemstones-10]]], and [[[[1d3]]t[Magic-Item-Table-A]]]. Output is like this:  This treasure hoard 2400 copper, 1500 silver, 30 gold, Peridot (500 GP), Alexandrite (500 GP), Black Pearl (500 GP), Black Pearl (500 GP), Alexandrite (500 GP), Aquamarine (500 GP), Aquamarine (500 GP), Topaz (500 GP), Topaz (500 GP), Topaz (500 GP), and 0. The Coins table has 3 inline rolls to generate the copper silver and gold. The gemstones and magic item tables both just output the text without rolling further inline amounts.  I did some testing where I changed things around to see if I could narrow it down.  [[1t[TreasureHoardCoins04]]], [[6t[Gemstones-10]]], and [[[[1d3]]t[Magic-Item-Table-A]]]. gives me the expected output. [[[[1d4]]t[TreasureHoardCoins04]]], [[6t[Gemstones-10]]], and [[[[1d3]]t[Magic-Item-Table-A]]]. gives me the expected output. [[[[1d4]]t[TreasureHoardCoins04]]], [[[[2d6]]t[Gemstones-10]]], and [[[[1d3]]t[Magic-Item-Table-A]]]. gives me the error.  If I do something like this and reorder the rolls:  [[[[2d6]]t[Gemstones-10]]], [[[[1d3]]t[Magic-Item-Table-A]]], [[1t[TreasureHoardCoins04]]] [[[[2d6]]t[Gemstones-10]]], [[1t[TreasureHoardCoins04]]], [[[[1d3]]t[Magic-Item-Table-A]]] everything is fine.  [[1t[TreasureHoardCoins04]]], [[[[1d3]]t[Magic-Item-Table-A]]], [[[[2d6]]t[Gemstones-10]]]  until this gives me the error again.  Hopefully that helps you track it down. 
1488201782
The Aaron
Pro
API Scripter
Hmm.. This is next on my list for scripts to work on.  I have Scott's changes to get rolled out and I want to rework part of it for the new indexing of objects.  Additionally, I should be able to write a preprocessor to fix  this bug  in practice, which might be what's going wrong for you.  I could replace all the sendChat() calls for inline rolls with my own inline roll expansion code, but I REALLY don't want to do that if I don't have to.