8,290
edits
m (remove beta modding category) |
mNo edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{Modding Info}} | {{Modding Info}}{{Modding Topic Prerequisites | Modding:C Sharp Scripting}} | ||
To create a wish, you define a <code>WishCommand</code> attribute on a public method. This method should either be void or bool. The enclosing class must also have the <code>HasWishCommand</code> attribute | |||
To create a wish, you define a <code> | |||
<syntaxhighlight lang="csharp"> | <syntaxhighlight lang="csharp"> | ||
using XRL.Wish; | |||
[HasWishCommand] | |||
public class MyWishHandler | public class MyWishHandler | ||
{ | { | ||
// Handles "testwish:foo" or "testwish foo" as a wish command | // Handles "testwish:foo" or "testwish foo" as a wish command | ||
[ | [WishCommand(Command = "testwish")] | ||
public static bool TestWishHandler(string rest) | public static bool TestWishHandler(string rest) | ||
{ | { | ||
Line 21: | Line 19: | ||
// Handles "testwish" with nothing else! (no string param) | // Handles "testwish" with nothing else! (no string param) | ||
[ | [WishCommand(Command = "testwish")] | ||
public static void TestWishHandler() | public static void TestWishHandler() | ||
{ | { | ||
Line 32: | Line 30: | ||
// no command -- uses the method name by default! | // no command -- uses the method name by default! | ||
[ | [WishCommand] | ||
public void inc() | public void inc() | ||
{ | { | ||
Line 38: | Line 36: | ||
} | } | ||
[ | [WishCommand] | ||
public void dec() | public void dec() | ||
{ | { | ||
Line 44: | Line 42: | ||
} | } | ||
[ | [WishCommand(Regex = @"other fancy match \d things"] | ||
public void Handle(System.Text.RegularExpression.Match match) | public void Handle(System.Text.RegularExpression.Match match) | ||
{ | { | ||
Line 54: | Line 52: | ||
The regular expression passed to the attribute is parsed using case insensitive matching. | The regular expression passed to the attribute is parsed using case insensitive matching. | ||
[[Category:Modding]] | |||
For another example of wish command, refer to the [[Modding:Tiles#Creating_a_Player-Tile]] topic. | |||
[[Category:Script Modding]] | |||
{{Modding Navbox}} | {{Modding Navbox}} |