Arguments, logging and random numbers¶
C# methods for a Run C# code step. See C# methods for how to use them.
TryGetArg¶
Reads one of the action's variables (the %name% words) by its name. The version with a type turns the value into that type for you, like text or a whole number.
bool TryGetArg<T>(string argName, out T value)
bool TryGetArg(string argName, out object? value)
Gives back: true and the value when the variable exists (and fits the type), otherwise false. Always false while Init() runs outside an action.
Example
if (CPH.TryGetArg("user", out string user))
{
CPH.LogInfo($"Hello {user}!");
}
SetArgument¶
Sets a variable (a %name% word) for the rest of this action, so later sub-actions can use it. Only works while an action runs, not from Init().
void SetArgument(string variableName, object? value)
Gives back: Nothing.
Example
CPH.SetArgument("prize", "a free song request");
GetSource¶
Tells you which kind of event started this action, like Twitch or Command. Gives None when you ran the action by hand.
EventSource GetSource()
Gives back: The event source, or None when it is unknown.
Example
var source = CPH.GetSource();
CPH.LogInfo($"Started by: {source}");
GetEventType¶
Tells you exactly which event started this action, like TwitchFollow or TwitchCheer. Gives None when it is unknown or you ran the action by hand.
EventType GetEventType()
Gives back: The event type, or None.
Example
var type = CPH.GetEventType();
CPH.LogInfo($"Event: {type}");
LogInfo¶
Writes a normal line to Cuebot's log. Handy to see what your code is doing.
void LogInfo(string message)
Gives back: Nothing.
Example
CPH.LogInfo("The raid alert started.");
LogWarn¶
Writes a warning line to Cuebot's log. Use it when something looks wrong but your code can go on.
void LogWarn(string message)
Gives back: Nothing.
Example
CPH.LogWarn("No game name was given, using Just Chatting.");
LogError¶
Writes an error line to Cuebot's log. Use it when something failed.
void LogError(string message)
Gives back: Nothing.
Example
CPH.LogError("Could not reach the song list.");
LogDebug¶
Writes a debug line to Cuebot's log, for extra details while you test your code.
void LogDebug(string message)
Gives back: Nothing.
Example
CPH.LogDebug("Checking the viewer list now.");
LogVerbose¶
Writes a very detailed line to Cuebot's log. In Cuebot this is the same as LogDebug.
void LogVerbose(string message)
Gives back: Nothing.
Example
CPH.LogVerbose("Loop step 3 done.");
Wait¶
Pauses your code for a number of milliseconds (1000 = 1 second). It stops early when the action is cancelled or the script runs out of time.
void Wait(int milliseconds)
Gives back: Nothing.
Example
CPH.Wait(2000);
CPH.LogInfo("Two seconds later.");
Between¶
Picks a random whole number between two numbers. Both ends can be picked. If you swap them by mistake, it still works.
int Between(int min, int max)
Gives back: A random whole number from min to max.
Example
int roll = CPH.Between(1, 6);
CPH.LogInfo($"You rolled a {roll}!");
NextDouble¶
Picks a random number from 0 up to (but not including) 1. Handy for chances, like a 25% win.
double NextDouble()
Gives back: A random number from 0 to just under 1.
Example
double chance = CPH.NextDouble();
CPH.LogInfo(chance < 0.25 ? "You win!" : "Try again.");
GetVersion¶
Gives you Cuebot's version number. (Streamer.bot gives its own version; Cuebot gives Cuebot's.)
string GetVersion()
Gives back: Cuebot's version as text.
Example
string version = CPH.GetVersion();
CPH.LogInfo($"Cuebot version {version}");