FunctionRegistry.RegisterFunction Method (String, FunctionCallback, FunctionScope, FunctionTiming)
Registers the specified callback to the given name, scope, and timing.
- Namespace: Dice
- Assembly: DiceRoller (in DiceRoller.dll)
Syntax
public void RegisterFunction(
string name,
FunctionCallback callback,
FunctionScope scope,
FunctionTiming timing
)
Parameters
- name
- Type: System.String
- Function name to register. Function names are case-insensitive.
- callback
- Type: Dice.FunctionCallback
- The method to be called whenever the function is called in a dice expression.
- scope
- Type: Dice.FunctionScope
- The scope of the function.
- timing
- Type: Dice.FunctionTiming
- When in the order of evaluation of a roll the function should be executed. Ignored for global functions.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | name is null .
|
ArgumentException | name is the empty string. |
InvalidOperationException | A function with the same name and scope has already been registered. |
Remarks
The short-hand FunctionScope.All and FunctionScope.Roll can be used to register the function for multiple scopes simultaneously, obviating the need for multiple calls to RegisterFunction().
The timing parameter only matters when registering a function with the Basic or Group scopes (both All and Roll include these scopes as well). When registering global functions, the timing is ignored and all global functions are executed in the order they are specified in the dice expression. For example, a(b(1d20)) + c()
executes b(1d20)
first, then a()
on the result of that, then c()
last.
There can only be one callback associated with any given function name and scope. It is an error to re-register a function, but a function can be removed and then registered again.