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

RecursiveTable - TypeError: Cannot read property 'id' of undefined

May 06 (5 years ago)

Edited May 06 (5 years ago)

Looks like this is crashing for me - I have had it crash on 2 separate occasions so far.

I am using a macro to roll treasure:

!rt[Delimiter:BR|EmptyDefault:Nothing] /w gm &{template:default}{{name=CR 5-10 Hoard}}{{coins=[[2d6*100]] Copper Pieces | [[2d6*1000]] Silver Pieces | [[6d6*100]] Gold Pieces | [[3d6*10]] Platinum Pieces}}{{treasure=[[1t[TREASURE-HOARD:-CR-5-10]]]}}

Which returns:


And is correctly rolling on the tables.

The following Macro:

!rt[Delimiter:BR|EmptyDefault:Nothing] /w gm &{template:default}{{name=CR 10-16 Hoard}}{{coins=[[4d6*1000]] Gold Pieces | [[5d6*100]] Platinum Pieces}}{{treasure=[[1t[TREASURE-HOARD:-CR-11-16]]]}}


Is causing the script to crash with the following output:

For reference, the error message generated was: TypeError: Cannot read property 'id' of undefined TypeError: Cannot read property 'id' of undefined at Object.d20.getWeightedTable (/home/node/d20-api-server/api.js:143:72) at Object.d20.getTableElementCount (/home/node/d20-api-server/api.js:130:14) at validateParseResult (eval at <anonymous> (/home/node/d20-api-server/api.js:157:1), <anonymous>:288:32) at parseRollString (eval at <anonymous> (/home/node/d20-api-server/api.js:157:1), <anonymous>:370:22) at Object.process (eval at <anonymous> (/home/node/d20-api-server/api.js:157:1), <anonymous>:1025:17) at _processRoll (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:1036:30) at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:976:10) at _findInlineRolls (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:991:11) at inlinefinalcallback (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:1102:7) at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:988:11)
TypeError: Cannot read property 'id' of undefined
at Object.d20.getWeightedTable (/home/node/d20-api-server/api.js:143:72)
at Object.d20.getTableElementCount (/home/node/d20-api-server/api.js:130:14)
at validateParseResult (eval at <anonymous> (/home/node/d20-api-server/api.js:157:1), <anonymous>:288:32)
at parseRollString (eval at <anonymous> (/home/node/d20-api-server/api.js:157:1), <anonymous>:370:22)
at Object.process (eval at <anonymous> (/home/node/d20-api-server/api.js:157:1), <anonymous>:1025:17)
at _processRoll (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:1036:30)
at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:976:10)
at _findInlineRolls (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:991:11)
at inlinefinalcallback (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:1102:7)
at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:988:11)

I can't see anything wrong with my tables that would be causing it.

As it works, but every now and then just crashes.

Which makes me think it IS something wrong with my table. (works when calling X and Y but not Z, if that makes sense?)

The table in question is this:


The actual table contents is a little different to how it looks in the image

For example, the first row reads:

The following art worth 250 GP each:<br>[[ [[2d4]]t[250 GP ART OBJECTS] ]]<br><br>And the following loot:<br>[[ [[1d4]]t[MAGIC-ITEM-TABLE-A] ]]<br>[[ [[1d6]]t[MAGIC-ITEM-TABLE-B] ]]

But the HTML elements don't show within the table when just viewing it.


The same thing happens with my TREASURE-HOARD:-CR-17+ table:

!rt[Delimiter:BR|EmptyDefault:Nothing] /w gm &{template:default}{{name=CR 17+ Hoard}}{{coins=[[12d6*1000]] Gold Pieces | [[8d6*1000]] Platinum Pieces}}{{treasure=[[1t[TREASURE-HOARD:-CR-17+]]]}}


As I said, I am fairly sure it's not the macro causing it.

Maybe something about my table entries that it doesn't like?

May 06 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

I think you're hitting some variant of this bug: https://app.roll20.net/forum/post/6778746/api-sendchat-returns-bad-results-to-callback-with-rollable-tables-expressions-with-inline-rolls

If you can pare it down to a reproducible case, we might be able to get eyes on it.  If you change all your table rolls to supply and inline roll as the argument, even if it's constant, that will probably prevent it from happening.  For example:

{{treasure=[[ [[1]]t[TREASURE-HOARD:-CR-17+]]]}}

Made a new rollable table with the section I thought was causing the crash.

Used the macro:

!rt[Delimiter:BR|EmptyDefault:Nothing] /w gm &{template:default}{{name=TEST}}{{coins=[[12d6*1000]] Gold Pieces | [[8d6*1000]] Platinum Pieces}}{{treasure=[[1t[Test-Table]]]}}

The table has 4 rolls:

The following gems worth 1000 GP each:<br>[[ [[3d6]]t[1000 GP GEMSTONES] ]]<br><br>And the following loot:<br>[[ [[1d8]]t[MAGIC-ITEM-TABLE-C] ]]
The following art worth 2500 GP each:<br>[[ [[1d10]]t[2500 GP ART OBJECTS] ]]<br><br>And the following loot:<br>[[ [[1d8]]t[MAGIC-ITEM-TABLE-C] ]]
The following art worth 7500GP each:<br>[[ [[1d4]]t[7500 GP ART OBJECTS] ]]<br><br>And the following loot:<br>[[ [[1d8]]t[MAGIC-ITEM-TABLE-C] ]]
The following gems worth 5000GP each:<br>[[ [[1d8]]t[5000 GP GEMSTONES] ]]<br><br>And the following loot:<br>[[ [[1d8]]t[MAGIC-ITEM-TABLE-C] ]]


So it's something about the formatting of this that is causing the issue, I think.

May 06 (5 years ago)

Edited May 06 (5 years ago)

Removed all but 1 entry on the table, still causing an error.
Remaining entry:

The following gems worth 1000 GP each:<br>[[ [[3d6]]t[1000 GP GEMSTONES] ]]<br><br>And the following loot:<br>[[ [[1d8]]t[MAGIC-ITEM-TABLE-C] ]]

Tried to roll outside of a macro using the following:

!rt /w gm [[1t[Test-Table]]]

Still crashes. Will continue to investigate.

Ha. Think I sussed it. I'm an idiot. (clearly in need of more coffee)


Table name was: 1,000 GP GEMSTONES

Macro was trying to call: [[ [[3d6]]t[1000 GP GEMSTONES] ]]


Fixed it, and now seems to be working fine. My error! Happy to close / delete this thread.

May 06 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

Oh, so that was the behavior for a table that didn't exist?  Yikes!   I'll have to try that and see if I can patch for it.  Honestly, with the bug I mentioned above, I've been considering doing the table rolls in the code anyway...

May 06 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

Glad you got your issue worked out.

Yeah, looks like it bombed out when the table didn't exist. Maybe throw some error handling in there. A simple try/catch should do the trick for this kind of thing I guess?

try {
Code block
}
catch (e) {
post to chat and/or API output conosle
}
May 06 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter
Yeah, probably a good idea. =D