How roll indices are assigned and resolved
How an inline
roll gets it’s index is intertwined with how inline rolls get sent to
the roll server. From what I’ve been able to deduce roll resolution
loops over three phases
Search, Request, Resolve
Search:
The parser searches the macro text from left to right until it finds an
inline roll that is ‘completable’. A completable roll is one without
any nested rolls, or whose nested rolls have been resolved. Once found
it is assigned an incrementing index starting at 0 and added to a list
of rolls to request. At this point if the newly indexed roll wasn’t
nested the search continues however if the newly indexed roll was a
nested roll search stops and moves onto the Request phase. If no further ‘completable’ rolls were found the parser still moves onto the Request phase.
Request:
The parser checks its list of rolls to request and its list of roll
results. If it has results that haven’t been resolved or no requests to
make, it makes no request. If there are rolls to request but no results
that are awaiting resolution all the rolls on the request list will be
sent to the roll server. However, this behaviour is different based on
if the inline roll is a calculation (eq [[ {2,4}k1 + 3 ]] ) or a random
roll (eq [[ 1d6 + 1t[table] ]]). Only random rolls actually get sent to
the roll server, calculations are put onto the list of results
immediately. So no requests will be made whilst there are unresolved
calculations. Whether a request was made or not, the parser moves onto
the Resolve phase.
Resolve: The parser will resolve
the lowest indexed unresolved result. If this was for an unnested
inline roll nothing happens, if this was a nested inline roll it will
replace the roll with the numeric result. In either case as long as a
result was resolved the parser will move back to the Search phase, otherwise roll resolution ends.
Some examples
[[0]] [[1]]
Search : All rolls are assigned an index
Request: No rolls to request, 2 results available
Resolve: Index 0 is resolved, no replacement
Search : Nothing found
Request: No rolls to request, 1 result available
Resolve: Index 1 is resolved, no replacement
Search : Nothing found
Request: No requests or results
Resolve: Nothing to do, end
[[1d4 index 0]] [[ [[4 index 1]] + 1d6 index 2]]
Search : Find indices 0, 1. 1 is nested
Request: Index 1 is calc, result is available
Resolve: Replace index 1 with numeric result
Search : Find index 2
Request: Request indices 0,2
Resolve: Resolve index 0, no replacement
Search : Nothing found
Request: Results available
Resolve: Resolve index 2, no replacement
Search : Nothing found
Request: No requests or results
Resolve: Nothing to do, end
[[0 index 0]] [[ [[1d4 index 1]] + 3 index 3]] [[2d1 index 2]]
Search : Find indices 0, 1. 1 is nested
Request: Index 0 is calc, result available
Resolve: Resolve index 0, no replacement
Search : [[ [[1d4 index 1]] + 3 index 3]] is not completable find [[2d1 index 2]]
Request: Request [[1d4 index 1]] and [[2d1 index 2]]
Resolve: Index 1, replace with numeric results
Search : Find index 3
Request: Have result indices 2, 3. 3 is calc
Resolve: Resolve index 2, no replacement
Search : Nothing found
Request: have results
Resolve: Resolve index 3, no replacement
Search : Nothing found
Request: No requests or results
Resolve: Nothing to do, end