new page

That_One_Nerd 2023-03-16 11:03:57 -04:00
parent 620cb70688
commit 5bb182bbc5

34
Modules.md Normal file

@ -0,0 +1,34 @@
# SrcMod/Modules
Modules in SrcMod are how commands are grouped. A module can have an id which must be prefixed before the command name and parameters when parsed. Modules are declared by applying the `ModuleAttribute` attribute in the namespace `SrcMod.Shell.Modules.ObjectModels` to a class. The classes can be static.
Here is an example:
```csharp
// Used for the `ModuleAttribute`.
using SrcMod.Shell.Modules.ObjectModels;
[Module("example1")]
public static class ExampleModule1
{
// Invoked by executing "example1 <command> <arguments>"
}
```
The `ModuleAttribute` attribute requires you to supply a `nameId`. This will be what prefixes the command name ID in a command string. Optionally, there is also a boolean `nameIsPrefix`, which by default is set to `true`. If the parameter is `false`, commands in that module will not require the module name ID to be prefixed.
```csharp
// Used for the `ModuleAttribute`.
using SrcMod.Shell.Modules.ObjectModels;
[Module("example2", false)]
public static class ExampleModule2
{
// The module ID is not a prefix.
// Invoked by executing "<command> <arguments>"
}
```
Inside the class will be the commands in that module.
---
**Note: When using the `srcmod.dll` to add additional custom modules, the new modules will not be recognized due to a reflection bug. This will be fixed in the near future (see issue #2).**