CPH refers to the original development name of Streamer.bot, ChannelPointsHandlerWhen you add a new Execute C# Code sub-action, you will be greeted with the following code snippet:
using System;
public class CPHInline
{
public bool Execute()
{
// your main code goes here
return true;
}
}
Within all C# code actions you have access to the CPH class, allowing you to make calls to internal Streamer.bot methods.
Execute()When your C# sub-action is executed, the Execute() method is always called.
This is where you should place your main code logic, as shown in the example below:
public bool Execute()
{
CPH.LogInfo("Hello from C#");
return true;
}
Normally this method returns true to allow execution of any subsequent sub-actions.
If for some reason you would like to cancel further execution, and skip any remaining sub-actions in the current action, you can return false.
public bool Execute()
{
if (someCondition) {
CPH.LogInfo("This action will now stop executing further sub-actions.");
return false; // Stop execution of further sub-actions
}
return true; // Allow further execution
}
You can also define your own custom methods within the CPHInline class, and call them from within the Execute() method.
public bool Execute()
{
CPH.LogInfo("Starting execution...");
CustomMethod();
return true;
}
public void CustomMethod()
{
CPH.LogInfo("Hello from a custom method!");
}
Within the C# code dialog, you have access to several button actions:
| Action | Description |
|---|---|
| Format Document | Automatically format your code with proper indentation |
| Find Refs | Attempt to automatically find some common references based on your using directives. |
| Compile | Test the compilation of your code and check for errors. |
| Save and Compile | Save your changes, and pre-compile the code so it's ready to go the first time the action is hit |
| Ok | Save your changes |
| Cancel | Discard your changes |
Explore some introductory video tutorials on using C# in Streamer.bot