maptool icon indicating copy to clipboard operation
maptool copied to clipboard

[Feature]: Add more control of what a table returns.

Open FullBleed opened this issue 1 month ago • 1 comments

Describe the Problem

Default table results are oddly opinionated.

Ranges can overlap and the result returned is always the last one encountered in cases where a roll is found in more than one row.

We should have more power to control how/what a table returns.

The Solution you'd like

Add a drop-down preference setting in the table to determine what result it returns with the table() function:

  • last : (Default; the current method that--in the case of a roll appearing in more than one Range--will return the last appearance)
  • first : (Return the first valid result encountered)
  • all : (Return a json of all results encountered)
  • strict : (Return an error if there is more than one valid result. This would help with error correcting a potentially "bad" table)

Alternatives that you've considered.

  1. Add a rollTable() function that rolls on a table with a resultType parameter.

rollTable(tableName, resultType)

resultType param options would mirror the options listed above (last, first, all, strict).

  1. Add some kind of getRawTable() function that would get the entire contents of a table and let us build our own UDFs to return results from tables in ways that we want. This seems like it would be terribly slow to do on the macro level and could be very memory intensive with large tables (defeating one of the key data-on-demand benefits of a table.)

Additional Context

No response

FullBleed avatar Nov 19 '25 18:11 FullBleed

As well as the table() function, the preference setting would also need to apply to the result of UI interactions with the table, i.e. double clicking on the table icon in the Tables window.

Regarding the second alternative considered and for info, there was a trusted function introduced in 1.18.0 which can return all raw data from a table; namely getTableEntries() so no need to consider adding another one! For example, to get all entries matching a roll is currently possible using something like:

[vRoll = d10]
[vAll = json.path.read(getTableEntries("D10"), strFormat("[*][?(@['min'] <= %{vRoll} && @['max'] >= %{vRoll})]"))]

Baaaaaz avatar Nov 19 '25 21:11 Baaaaaz