Manual:Using Code Modules

From VerbotWiki

As of version 4.1.0.7 Verbots now supports Code Modules, which are really cool, and really powerful. You can see a full sample of using Code Modules in the Julia CSharp Suppliment KB here (http://www.verbots.com/forums/dload.php?action=file&file_id=112).

Here is a little about how to use them inside your Verbot Scripts using the above KB as a sample:

Open the julia_csharp_supplement kb in the Editor: You will notice the MyMath.vcm file attached as a resource file, I need this so that I can bring in the code from the MyMath code module file and call it from my main knowledgebase.

verboteditor_shot_jcs.jpg

Double click on the MyMath file in the resouce list box to bring it up in the code module editor.

verbotcmeditor_shot_mymath.jpg

Notice the top left box is the module name of the currently opened code module. Also in the lower left of the Code module Editor you'll notice a list of the Functions (or methods) available in the code module. Once you select one, the details of that function will update to reflect the selected function.

Functions have the following properties: Name, ParameterList, Return type, and Code

The Name and parameter list determine how you will call this module, for example in the case of the Add method I would call it from my KnowledgeBase by using the ModuleName followed by a dot (".") followed by the MethodName, followed by the parameter list separated by commas, and surrounded by parens, and finally a semi-colon to end the statement.

The Add Call Looks like this:

MyMath.Add("1", "2");

note my Add function takes strings so it's easy to call from the KnowledgeBase and from within variable captures. This just will return the answer, so to print it from within the Verbot KB I'll need to do Console.Write(MyMath.Add("1", "2")); and enclose it within csharp tags.

Putting it all together, () the call to add looks like this:

<?csharp Console.Write(MyMath.Add("1", "2")); ?>


Double Click the Output of the "test module" rule to see the example of how it's done.