< Dice‎ | FunctionRegistry
Revision as of 19:18, 24 April 2017 by Skizzerz (talk | contribs) (Created page with "{{APIdoc|FunctionRegistry.RegisterFunction Method (String, FunctionCallback, FunctionScope, FunctionTiming)}} Registers the specified callback to the given name, scope, and ti...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

FunctionRegistry.RegisterFunction Method (String, FunctionCallback, FunctionScope, FunctionTiming)

From DiceRoller Documentation

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: FunctionCallback
The method to be called whenever the function is called in a dice expression.
scope
Type: FunctionScope
The scope of the function.

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.

See Also