Modding:Wishes: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
(10 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{Modding Info}}{{Modding Topic Prerequisites | Modding:C Sharp Scripting}} | |||
To create a wish, you define a | 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 | ||
<syntaxhighlight lang="csharp"> | <syntaxhighlight lang="csharp"> | ||
using XRL.Wish; | |||
[ | [HasWishCommand] | ||
public | public class MyWishHandler | ||
{ | { | ||
// Handles "testwish:foo" or "testwish foo" as a wish command | |||
[WishCommand(Command = "testwish")] | |||
public static bool TestWishHandler(string rest) | |||
Popup.Show("Matched: " + | { | ||
Popup.Show("Matched: " + rest); | |||
// if we dont return true, other wishes will also parse this wish message | // if we dont return true, other wishes will also parse this wish message | ||
return true; | return true; | ||
} | |||
// Handles "testwish" with nothing else! (no string param) | |||
[WishCommand(Command = "testwish")] | |||
public static void TestWishHandler() | |||
{ | |||
Popup.Show("Matched it the short way"); | |||
// if we return void, it assumes we handled it | |||
} | |||
// showing of non-static also! | |||
public int count = 0; | |||
// no command -- uses the method name by default! | |||
[WishCommand] | |||
public void inc() | |||
{ | |||
Popup.Show(count++); | |||
} | |||
[WishCommand] | |||
public void dec() | |||
{ | |||
Popup.Show(count--); | |||
} | |||
[WishCommand(Regex = @"other fancy match \d things"] | |||
public void Handle(System.Text.RegularExpression.Match match) | |||
{ | |||
Popup.Show(match.Groups[0].ToString()); | |||
} | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
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. | ||
For another example of wish command, refer to the [[Modding:Tiles#Creating_a_Player-Tile]] topic. | |||
[[Category:Script Modding]] | |||
{{Modding Navbox}} |
Latest revision as of 19:03, 24 March 2021
This page is about modding. See the modding overview for an abstract on modding. |
This page is about modding. See the modding overview for an abstract on modding.
This page is about modding. See the modding overview for an abstract on modding.
For best results, it's recommended to have read the following topics before this one:
To create a wish, you define a WishCommand
attribute on a public method. This method should either be void or bool. The enclosing class must also have the HasWishCommand
attribute
using XRL.Wish;
[HasWishCommand]
public class MyWishHandler
{
// Handles "testwish:foo" or "testwish foo" as a wish command
[WishCommand(Command = "testwish")]
public static bool TestWishHandler(string rest)
{
Popup.Show("Matched: " + rest);
// if we dont return true, other wishes will also parse this wish message
return true;
}
// Handles "testwish" with nothing else! (no string param)
[WishCommand(Command = "testwish")]
public static void TestWishHandler()
{
Popup.Show("Matched it the short way");
// if we return void, it assumes we handled it
}
// showing of non-static also!
public int count = 0;
// no command -- uses the method name by default!
[WishCommand]
public void inc()
{
Popup.Show(count++);
}
[WishCommand]
public void dec()
{
Popup.Show(count--);
}
[WishCommand(Regex = @"other fancy match \d things"]
public void Handle(System.Text.RegularExpression.Match match)
{
Popup.Show(match.Groups[0].ToString());
}
}
The regular expression passed to the attribute is parsed using case insensitive matching.
For another example of wish command, refer to the Modding:Tiles#Creating_a_Player-Tile topic.
|