PDA

View Full Version : Return the result of a table roll inside script



MadBeardMan
May 24th, 2021, 10:13
Morning All,

Is there a way to handle the result of a Table roll?

Inside Traveller we have the Critical Tables and rather than build a new roll type, it would just be simpler if I could roll the table and get back the result.

I can't see how to do this as there's no documentation that I can find on the Table Manager.

This code rolls the dice and outputs the result to the Chat, perfect, now I just need to know what it rolled.


TableManager.processTableRoll("", "Spacecraft Critical Hits Location");

Cheers,
MBM

Trenloe
May 24th, 2021, 13:17
Rolling on a table is like other rolls - they're asynchronous and the result is processed in the registered ActionsManager result handler, in this case onTableRoll, and you can only have one result handler.

So, short of extending onTableRoll to handle another type of output, you may just be better "rolling" using a math.random and then using the result to do the lookup yourself - directly at the table. Or, if the data in the table doesn't change, you may want to code it as a LUA record (LUA table) and access the data directly through code. The older Star Wars EotE ruleset did this for it's critical hit resolution - there's an example extension for the LUA table here: https://www.fantasygrounds.com/forums/showthread.php?25514-Star-Wars-Edge-of-the-Empire-ruleset-Custom-Critical-Text-extension The code to do the lookup is in the ruleset - but it's just a simple math.random call and then finds the entry in the LUA table that is within the d100_start and d100_end results.

MadBeardMan
May 24th, 2021, 17:49
Rolling on a table is like other rolls - they're asynchronous and the result is processed in the registered ActionsManager result handler, in this case onTableRoll, and you can only have one result handler.

So, short of extending onTableRoll to handle another type of output, you may just be better "rolling" using a math.random and then using the result to do the lookup yourself - directly at the table. Or, if the data in the table doesn't change, you may want to code it as a LUA record (LUA table) and access the data directly through code. The older Star Wars EotE ruleset did this for it's critical hit resolution - there's an example extension for the LUA table here: https://www.fantasygrounds.com/forums/showthread.php?25514-Star-Wars-Edge-of-the-Empire-ruleset-Custom-Critical-Text-extension The code to do the lookup is in the ruleset - but it's just a simple math.random call and then finds the entry in the LUA table that is within the d100_start and d100_end results.

Hi Chap,

Thanks for letting me know.

I don't like hidden results, so I'll add another dice roll type and plug all that in, I can re-task some existing code.

And the idea of the Lua table is spot on, I already have one, that shows what critical location and what effect depending on the level. Hence if I could get the dice roll from the table then it's just linking the two.

Cheers,
MBM

CaptJack2883
May 25th, 2021, 08:57
I have been doing a custom roll type by assigning a custom string value to rRoll.sType, then making my own result handler to pick up those rolls. Perhaps you can do something similar?