Click or drag to resize

TriggerHandler

[This is preliminary documentation and is subject to change.]

TriggerHandlers handle the logic associated with each Trigger. They take a delegate that takes one parameter TriggerReader.

Optional section title

Add one or more sections with content

Brief Intro to TriggerReader

TriggerReader is like BinaryReader. TriggerReader is used in retrieving the values associated with a Trigger. This is done through the 3 main Read* methods. The methods reader.PeekString, reader.PeekNumber or reader.PeekVariable return boolean if the next value is the desired type. Using those methods help avoid the Exception that is thrown if you try to read a value that doesn't exist.

In this example "trigger" points to a Trigger (5:999) set %testVariable to 123 and print {This is a String}.

C#
TriggerReader reader = new TriggerReader(trigger);
Monkeyspeak.Variable varValue = reader.ReadVariable(); // This would return a reference to %testVariable
double numValue = reader.ReadNumber(); // This would return 123
string stringValue = reader.ReadString(); // This would return "This is a String"

Trying to read these values out of order would cause an exception to be raised. This allows you to have some actual structure when processing Triggers.

For example if you add a 0, "Hello World", and %userName* to your trigger. You would read it like this:

C#
triggerReader.ReadNumber(); // Number is 0
triggerReader.ReadString(); // String is "Hello World"
triggerReader.ReadVariable(); // Variable is %userName

If however you decided to try to read the first value 0 as a String

triggerReader.ReadString(); // TriggerReaderException would be thrown here.

Sub-section 2

Sub-section content.