Modding:Wishes: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
(Created page with "Creating your own wishes requires 2.0.200.24 or greater. To create a wish, you define a `XRL.World.Capabilities.WishHandler` attribute on a public static class: <syntaxhighl...")
 
mNo edit summary
Line 1: Line 1:
Creating your own wishes requires 2.0.200.24 or greater.
Creating your own wishes requires 2.0.200.24 or greater.


To create a wish, you define a `XRL.World.Capabilities.WishHandler` attribute on a public static class:
To create a wish, you define a `XRL.World.Capabilities.WishHandler` attribute on a public class, you pass two parameters, a RegularExpression pattern string, and a Method Name which should take a successful Match if one is found.  Your method should return true if you handled the wish.


<syntaxhighlight lang="csharp">
<syntaxhighlight lang="csharp">

Revision as of 01:07, 17 April 2020

Creating your own wishes requires 2.0.200.24 or greater.

To create a wish, you define a `XRL.World.Capabilities.WishHandler` attribute on a public class, you pass two parameters, a RegularExpression pattern string, and a Method Name which should take a successful Match if one is found. Your method should return true if you handled the wish.

[XRL.World.Capabilities.WishHandler(@"^mytestwish$", "TestWishHandler")]
public static class MyWishHandler
{
   // the method should be public static, return a bool, and take a "Match" or it will not get called
   public static bool TestWishHandler(System.Text.RegularExpressions.Match match)
   {
     Popup.Show("Matched: " + match.Groups[0].ToString());
     // if we dont return true, other wishes will also parse this wish message
     return true;
   }
}

The regular expression passed to the attribute is parsed using case insensitive matching.