Difference between revisions of "API"
(Created page with "After downloading the package via NuGet, you can use the following API in order to roll dice and view those dice results. All relevant classes are found the Dice namespace, wh...") |
|||
Line 11: | Line 11: | ||
== Adding functions == | == Adding functions == | ||
− | To add functions, make use of the [[API/FunctionRegistry/RegisterType|FunctionRegistry.RegisterType]] or [[API/FunctionRegistry/RegisterFunction|FunctionRegistry.RegisterFunction]] methods. | + | To add functions, make use of the [[API/FunctionRegistry/RegisterType|FunctionRegistry.RegisterType]] or [[API/FunctionRegistry/RegisterFunction|FunctionRegistry.RegisterFunction]] methods. The first method (RegisterType) makes it easy to register numerous functions all at once. |
Revision as of 03:27, 8 April 2017
After downloading the package via NuGet, you can use the following API in order to roll dice and view those dice results. All relevant classes are found the Dice namespace, which you can quickly access by adding using namespace Dice;
at the top of your files.
Rolling dice
To roll dice, use the Roller.Roll method. This method is static and is the main entry point to using the library.
Getting results
The Roller.Roll method returns a RollResult object, which contains the final roll value as well as the dice rolled. Generally, this is enough information to view and display results, however more fine-grained information can be obtained by walking through the roll tree. For example, in the dice expression (1d8)d6
, a 1d8 is rolled, and then that many d6s are rolled. However, the RollResult will only contain the values of the d6s, it won't contain the value of the d8. You could figure it out by looking at the number of d6s there are, but it is also possible to directly inspect the d8 by walking the dice abstract syntax tree.
Configuring the roller
To configure roller settings, set the various properties on Roller.Config. This lets you change the various dice limits as well as what is used to resolve macros.
Adding functions
To add functions, make use of the FunctionRegistry.RegisterType or FunctionRegistry.RegisterFunction methods. The first method (RegisterType) makes it easy to register numerous functions all at once.