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

1469462228
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Hey Gary, Sorry it's taking me awhile to get back to you; lab work got a little crazy, and I got a little too deep into working on updating another script. Could you post up the exact macro that you are using to get the output in your reply  here ? I'm not getting the bug to replicate using the macro I put in. Could you also post up a tableExport of your 500GP-GemStone table? it doesn't seem to be in the exports already posted. Thanks, Scott
Scott here are the things you asked for-  m --250GP-Art-Object --Large gold bracelet worth 250GP --1 -- !import-table-item --250GP-Art-Object --Silver necklace with a gemstone pendant worth 250GP --1 -- !import-table-item --250GP-Art-Object --Bronze crown worth 250GP --1 -- !import-table-item --250GP-Art-Object --Silk robe with gold embroidery worth 250GP --1 -- !import-table-item --250GP-Art-Object --Large well-made tapestry worth 250GP --1 -- !import-table-item --250GP-Art-Object --Bra ss mug with jade inlay worth 250GP --1 -- !import-table-item --250GP-Art-Object --Box of turquoise animal figurines worth 250GP --1 -- !import-table-item --250GP-Art-Object --Gold bird cage with electrum filigree worth 250GP --1 --+ !import-table --Magic-Item-Table-I --hide!import-table-item --Magic-Item-Table-I --Defender --5 -- !import-table-item --Magic-Item-Table-I --Hammer of Thunderbolts --5 -- !import-table-item --Magic-Item-Table-I --Luck Blade --5 -- !import-table-item --Magic-Item-Table-I --Sword of Answering --5 -- !import-table-item --Magic-Item-Table-I --Holy Avenger --3 -- !import-table-item --Magic-Item-Table-I --Ring of Djinni Summoning --3 -- !import-table-item --Magic-Item-Table-I --Ring of Invisibility --3 -- !import-table-item --Magic-Item-Table-I --Ring of Spell Turning --3 -- !import-table-item --Magic-Item-Table-I --Rod of Lordly Might --3 -- !import-table-item --Magic-Item-Table-I --Staff of the Magi --3 -- !import-table-item --Magic-Item-Table-I --Vorpal Sword --3 -- !import-table-item --Magic-Item-Table-I --Belt of Cloud Giant Strength --2 -- !import-table-item --Magic-Item-Table-I --Armor +2 Breastplate --2 -- !import-table-item --Magic-Item-Table-I --Armor +3 Chain Mail --2 -- !import-table-item --Magic-Item-Table-I --Armor +3 Chain Shirt --2 -- !import-table-item --Magic-Item-Table-I --Cloak of Invisibility --2 -- !import-table-item --Magic-Item-Table-I --Crystal ball (legendary version) --2 -- !import-table-item --Magic-Item-Table-I --Armor +1 Half Plate --2 -- !import-table-item --Magic-Item-Table-I --Iron Flask --2 -- !import-table-item --Magic-Item-Table-I --Armor +3 Leather --2 -- !import-table-item --Magic-Item-Table-I --Armor +1 Plate --2 -- !import-table-item --Magic-Item-Table-I --Robe of the Archmagi --2 -- !import-table-item --Magic-Item-Table-I --Rod of Resurrection --2 -- !import-table-item --Magic-Item-Table-I --Armor +1 Scale Mail --2 -- !import-table-item --Magic-Item-Table-I --Scarab of Protection --2 -- !import-table-item --Magic-Item-Table-I --Armor + 2 splint --2 -- !import-table-item --Magic-Item-Table-I --Armor +2 Studded Leather --2 -- !import-table-item --Magic-Item-Table-I --Well of Many Worlds --2 -- !import-table-item --Magic-Item-Table-I --<%%91%%><%%91%%>1t<%%91%%>Magic-Armor-Table-I<%%93%%><%%93%%><%%93%%> --1 -- !import-table-item --Magic-Item-Table-I --Apparatus of Kwalish --1 -- !import-table-item --Magic-Item-Table-I --Armor of Invulnerability --1 -- !import-table-item --Magic-Item-Table-I --Belt of Storm Giant Strength --1 -- !import-table-item --Magic-Item-Table-I --Cubic Gate --1 -- !import-table-item --Magic-Item-Table-I --Deck of Many Things --1 -- !import-table-item --Magic-Item-Table-I --Efreeti Chain --1 -- !import-table-item --Magic-Item-Table-I --Armor of resistance (Half Plate) --1 -- !import-table-item --Magic-Item-Table-I --Horn of Valhalla (iron) --1 -- !import-table-item --Magic-Item-Table-I --Instrument of the Bards (Ollamh Harp) --1 -- !import-table-item --Magic-Item-Table-I --Ioun Stone greater absorption --1 -- !import-table-item --Magic-Item-Table-I --Ioun Stone Mastery --1 -- !import-table-item --Magic-Item-Table-I --Ioum Stone Regeneration --1 -- !import-table-item --Magic-Item-Table-I --Plate Armor of Etherealness --1 -- !import-table-item --Magic-Item-Table-I --Plate Armor of Resistance --1 -- !import-table-item --Magic-Item-Table-I --Ring of Air Elemental Command --1 -- !import-table-item --Magic-Item-Table-I --Ring of Earth Elemental Command --1 -- !import-table-item --Magic-Item-Table-I --Ring of Fire Elemental Command --1 -- !import-table-item --Magic-Item-Table-I --Ring of Three Wishes --1 -- !import-table-item --Magic-Item-Table-I --Ring of Water Elemental Command --1 -- !import-table-item --Magic-Item-Table-I --Sphere of Annihilation --1 -- !import-table-item --Magic-Item-Table-I --Talisman of Pure Good --1 -- !import-table-item --Magic-Item-Table-I --Talisman of the Sphere --1 -- !import-table-item --Magic-Item-Table-I --Talisman of Ultimate Evil --1 -- !import-table-item --Magic-Item-Table-I --Tome of the Stilled Tongue --1 -- !import-table --Magic-Armor-Table-I --hide !import-table-item --Magic-Armor-Table-I --Armor +2 Half Plate --2 -- !import-table-item --Magic-Armor-Table-I --Armor +2 Plate --2 -- !import-table-item --Magic-Armor-Table-I --Armor +3 Studded Leather --2 -- !import-table-item --Magic-Armor-Table-I --Armor +3 Breastplate --2 -- !import-table-item --Magic-Armor-Table-I --Armor +3 Splint --2 -- !import-table-item --Magic-Armor-Table-I --Armor +3 Half Plate --1 -- !import-table-item --Magic-Armor-Table-I --Armor +3 Plate --1 -- QUESTION- WHY IS THIS TABLE INDENTED ON IMPORT? THE OTHERS WEREN'T !import-table --500GP-Gemstones --show!import-table-item --500GP-Gemstones --Alexandrite (transparent dark green) worth 500GP --1 --!import-table-item --500GP-Gemstones --Aquamarine (transparent pale blue-green) worth 500GP --1 --!import-table-item --500GP-Gemstones --Black pearl (opaque pure black) worth 500GP --1 --!import-table-item --500GP-Gemstones --Blue spinel (transparent deep blue) worth 500GP --1 --!import-table-item --500GP-Gemstones --Peridot (transparent rich olive green) worth 500GP --1 --!import-table-item --500GP-Gemstones --Topaz (transparent golden yellow) worth 500GP --1 --
1469470027
The Aaron
Pro
API Scripter
Not sure about the indent question, but posting as code might help: When posting Macros, Dice Expressions, or API Code Snippets, consider using the Code format option, available by clicking the paragraph symbol ( ¶ ) and selecting it from the list.
The table I am having trouble with is the one that indented. Could it be the reason why the table returns a 0?
I am trying to create a bit of code that rolls a random encounter table.  Everything is going mostly well, except whenever I roll the table it is visible to everyone.. which kinda ruins the surprise.  I have tried to set it up as a whisper, but it seems to fail to whisper. !rt /w gm &{template:default} {{name=Random Enc. (Rivers Run Red)}} {{Forest=[[ 1t[rEn-RRr-Forest] ]]}} {{Plains=[[ 1t[rEn-RRr-Plains] ]]}} {{Hills=[[ 1t[rEn-RRr-Hills] ]]}} {{Lakes & Rivers=[[ 1t[rEn-RRr-LakesR] ]]}} Is the code I'm using, am I doing something wrong?  Also, I've noticed parsing issues also when using this with the /emote and /desc as well.  It adds this using the proper formatting but it prepends it with the name of the person "sending" the message.  I am not sure if this is as intended or a bug.  But I just thought I'd throw it out here. P.S.,  Also, I am nearly done crafting a set of random encounter tables for the first three books of Kingmaker, I'd be happy to share the encounter tables with anyone who would like.  I also have the Kingdom events and Building Events tables created.  Although I'm not sure if I got the Kingdom Events table correct.
1469633161
The Aaron
Pro
API Scripter
hmm.. I'll have a poke at this soon.  I've roped Scott into looking at some other things (and he's got a modified version that might fix this...) so he may have some fresher insight.
1469635349
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yep, my  modified version respects whispers when roll templates are used, the new version I'm working on for Aaron will as well when it is eventually done. That code linked above also allows rolling on tables with a modifier by putting it inside the inline roll brackets: [[1t[tableName]+mod]] you must have a + or - between the table call and the mod, and mod can be any number or inline roll (there is weirdness if you try using floor/ceil in it though).
1469643438
The Aaron
Pro
API Scripter
Ah!  I'm so out of touch with it I completely missed the roll template. =D
1469644996
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
heh, not like you don't have a ton of irons in the fire :)
1469645234
The Aaron
Pro
API Scripter
Too right!  Hoping to ditch most of them soon and get back to the scripting!
I get no response when I try to use this script, even in a completely new game. Does it still work?
1473649863
The Aaron
Pro
API Scripter
It should. What command are you running?  If you take the ! off the front, what output do you get?
I set up a new game, added the ResursiveRolls script to the API, created a rollable table called "test", gave it one item "[[ 3d6 ]]", then ran the command "!rt The roll is [[ 1t[test] ]]". There is no output. Removing the !, I get:  rt The roll is [[ 3d6 ]] I just checked the API console, and I get the error:  SyntaxError: Expected "[" or [ |\t] but "3" found.
1473679324
The Aaron
Pro
API Scripter
This is a bug with the sendChat() function in the API. rewrite your online rolls without spaces and it should be fine. 
Thanks, that worked. That's a nasty bug—one slip and it brings the API to a screeching halt!
1473683703
The Aaron
Pro
API Scripter
Tell me about it: <a href="https://app.roll20.net/forum/post/2217884/api-reg" rel="nofollow">https://app.roll20.net/forum/post/2217884/api-reg</a>...
1474007759
Tetsuo
Forum Champion
Hey, is it possible to use this in conjunction with the Power Cards api? I want something like !power {{ --whisper|gm --name|You've found: -- #?{Number of items}|!rt [[1t[Items-in-a-Giant's-Bag] ]] }}
1474007939
The Aaron
Pro
API Scripter
Try: !rt !power --whisper|gm --name|You've found: -- #?{Number of items}| [[1t[Items-in-a-Giant's-Bag] ]] That's either going to work, or not. &nbsp;If it doesn't work, then no, you can't. &nbsp;=/
1474008641
Tetsuo
Forum Champion
The Aaron said: Try: !rt !power --whisper|gm --name|You've found: -- #?{Number of items}| [[1t[Items-in-a-Giant's-Bag] ]] That's either going to work, or not. &nbsp;If it doesn't work, then no, you can't. &nbsp;=/ It didn't work. And it reeeeeeeeeeally didn't work. It completely crashed my chrome tab and gave me the "Aw Snap!" crash tab. Thanks for trying!
This is brilliant. &nbsp;Thank you. &nbsp;Two things. If you run !rt without any flags it breaks all the API scripting forcing a restart, maybe have !rt without any flags spit out a help screen by default? &nbsp;Here is the error: TypeError: Cannot read property 'get' of undefined TypeError: Cannot read property 'get' of undefined at handleInput (apiscript.js:2192:42) at eval (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:105:34), &lt;anonymous&gt;:65:16) at Object.publish (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:105:34), &lt;anonymous&gt;:70:8) at /home/node/d20-api-server/api.js:1200:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546) at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489) at Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425) at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:111:461 My second question - as it isn't clear to me from this thread or documentation - can I use this for complex random encounters? &nbsp;For example, I am running Out of the Abyss which is heavy on the random encounters when wandering the Underdark. &nbsp;They look something like this: Table1 1 No encounter 2 Creature -&gt; roll 1d20 on tableCreature 3 Terrain -&gt; roll 1d20 on tableTerrain 4 Creature and Terrain -&gt; roll once on both tableCreature and tableTerrain. tableCreature 1 mob1 2 mob2 with 25% chance of treasure -&gt; if true roll on tableTreasureA 3 mob3 but a random type of mob -&gt; roll on tableRace to determine if human, elf, or dwarf. 4 mob4 etc. Rolling Creature on Table1 should then trigger a roll on tableCreature. &nbsp;If mob2 is rolled then that should trigger a roll to see if the mob has treasure, if so, it would then roll on the tableTreasureA. Rolling mob3 on tableCreature should trigger another roll on tableRace to determine if it is a human, elf or dwarf. Rolling Creature and Terrain on Table1 triggers two separate rolls on tableCreature and tableTerrain which may trigger further rolls as explained above. All these tables are created as rollable tables in roll20. &nbsp;Hope that's clear! Thanks :)
1474203242

Edited 1474203437
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yes. It expands all inline rolls, so just put the nested table rolls in as inline rolls. Your table1 entries will look like this: Table1 1 No encounter 2 [[1t[tableCreature] ]] 3 [[1t[tableTerrain] ]] 4 [[1t[tableCreature] ]] in&nbsp;[[1t[tableTerrain] ]] As for !rt by itself, the script's in the final stages of a pretty major overhaul. I'll see about making sure this gets put in. I use this for my encounter generation as well as for shop inventory I've got around 200 tables for my pathfinder game's random item generation. As Aaron's OP says, it will only expand down to a certain level of nesting, 10 or 11 levels I believe.
1474203748
The Aaron
Pro
API Scripter
What Scott said. Weird it would crash without input, definitely gonna make sure that's fixed.&nbsp;
Great! Thank you both!
Hi, is there an automated way to test the script by chance? &nbsp;For example going through each variable and checking them (apart from me clicking the macro to run it)? Is there also a way to get more information from the API (or external app) when there is a syntax error, sometimes it isn't clear where the issue is from the error. Thanks.
1474550291
The Aaron
Pro
API Scripter
How do you mean? &nbsp;Just test that it's running? !rt --help or test that it's working? !rt [[1d6]] working or test what will be expanded for a particular table? &nbsp;That takes a bit more work. &nbsp;You can run what you would pass to the script without the command: Expand this table [[1t[Dwarf-Surname] ]] and get a result like: Expand this table [[1t[Dwarf-Surname-First] ]][[1t[Dwarf-Surname-Second] ]] Then run that through chat to see what it expands to: Expand this table [[1t[Dwarf-Surname-First] ]][[1t[Dwarf-Surname-Second] ]] and check the output: Expand this table [Noble][basher] As for getting better errors, I feel you pain. &nbsp;There isn't much more that can be easily done. &nbsp;I have some ideas about this, but it will have to wait until I finish my rewrite (hopefully by the end of the year).
1474550644
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The Aaron said: As for getting better errors, I feel you pain. &nbsp;There isn't much more that can be easily done. &nbsp;I have some ideas about this, but it will have to wait until I finish my rewrite (hopefully by the end of the year). I'll be interested to see what you come up with.
Hi Aaron, Just some way to run through each possible table list and all the nested tables to check the results of each one. &nbsp;I ask because I am seeing this error when running one of the table&nbsp;macros but as best I can tell all are formatted correctly and the error feedback isn't specific enough for me to pinpoint the problem, however this error brings down the whole API forcing me to restart which means I can't use it in a real game just yet: SyntaxError: Expected "[" or [ |\t] but "1" found. undefined Here are the tables which I have run manually in chat and all look good: (of course you will look at the tables, see something I didn't see and then I am going to feel stupid, but that's fine :) And it would save time for some of these bigger nested tables to be able to run an automated script to test it (sorry I am from a devOps background so whenever I see unrealised automation potential it irks me - my problem not yours :)
1474594450
The Aaron
Pro
API Scripter
Try changing this: [[ 1t[dungeon-hazard] ]] with this: [[1t[dungeon-hazard] ]] and the like. &nbsp;It's a&nbsp; bug in the sendchat() function on Roll20's side. &nbsp;
1474594482

Edited 1474594641
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Hi Michael, Do you get this error every time you run the script? If not, are there entries that it doesn't happen on? Woop, Aaron's probably got the right of it. Good rule of thumb, don't do spaces at the start of an inline roll. -scott
Fixed, thanks :)
1474601452
The Aaron
Pro
API Scripter
Woot! Happy Rolling!
It doesn't quite seem to respect the /desc function the way I would expect... Any thoughts on this, or is it something with the sendChat function that I'll just have to live with? What I was expecting from this command !rt [[1t[loot]]]gp is on the goblin was something like&nbsp; /desc 4gp is on the goblin but what I got was more akin to&nbsp; /desc&nbsp;&lt;playername&gt; 4gp is on the goblin.
1475334865

Edited 1475334883
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The current version has some issues with slash commands. Aaron and I have been working on a rewrite that will respect slash commands, roll templates and general formatting better as a side effect of the new recursion methods that will be used.
Looking forward to seeing that Scott
1475350232
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yeah, I think it'll fix your issue as well Gary(hoping so at least)
I may have missed this. In the original version (thanks The Aaron for the help this week) the whispers to gm don't work; which is what brought me to this thread. With the updated version that Scott C. posted, the whispers work, but tables that roll [[[[2d6]]t[table] ]] that worked in the original now just return the same item 2d6 times.&nbsp; Is there a way to get the best of both worlds?
1476412216
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Hmm, never noticed that about my hacked version, thanks for pointing it out. Sometime soon (once he's recovered from moving and catching up on other scripts) there should be a new version coming out that will respect all slash commands, roll templates, and (I can confirm) properly does the XdY number of table rolls.
1476417696
The Aaron
Pro
API Scripter
(Totally on my todo list... ping me tomorrow Scott!)
1477714126

Edited 1477714139
Is there a reason why the /w gm would fail with the !rt if you have a bunch of formatting stuff from the shaped character sheet from 5E? !rt /w gm &{template:5e-shaped}{{title=Cantrip Scrolls}}{{text_top=[[4t[SpellsLevel0]]]}} This fails to whisper without errors, just not a whisper !rt /w gm&nbsp;[[?{Rolls|1}t[SpellsLevel0]]] this whispers fine
1477714977

Edited 1477714992
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
There's a problem with the handling of roll templates in conjunction with slash commands in the current iteration. Currently the roll template overrides the slash commands. It's on the docket for the next version.
This is wonderful. If only there was a way to get tables to call from character sheet attributes &gt;_&gt; It would save me such a headache.
1478886984
The Aaron
Pro
API Scripter
How do you mean, Kiyomi?
Well for example, something I was trying to do for my campaign. Monsters can carry up to four items, Common, Uncommon, Rare and Very Rare that all have a different drop rate but I didn't want to create a separate table for every monster so if I could use @{selected|rareitem} or something as the result of a rollable table and it could call the specific item from the monster sheet it would save having to cross reference a loot table.
Also I'd just like to say Aaron that I love so many of your scripts. I use several in my RPG and they're all amazing.
1478887791
The Aaron
Pro
API Scripter
Thanks, happy to help! &nbsp;=D So the biggest problem there is the @{selected} part, but it's not impossible. &nbsp;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. &nbsp;=D
1478887968

Edited 1478887986
Kiyomi N.
Sheet Author
Well the reason I said selected is because how else would it know which token/monster to draw it's loot from? I have a macro I used right now that when a player kills a monster it informs them that it is now deceased, reports how much XP and Gil they received from it and (ideally) what loot drops. But I already use @[selected} to draw it's name, XP and Gil values to send to the chat so it made sense to use it for the loot too. If you figure something out I'd be most grateful!
1478888428
The Aaron
Pro
API Scripter
Yeah, @{selected} is the only way it could work generically.&nbsp;
I thought as much...