Difference between revisions of "API"
m |
|||
Line 1: | Line 1: | ||
− | 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 [[ | + | 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|Dice namespace]], which you can quickly access by adding {{cs|using Dice;}} at the top of your files. |
== Rolling dice == | == Rolling dice == |
Revision as of 07:24, 9 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 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.DefaultConfig. 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.