Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Ik1497 authored Jan 7, 2024
2 parents 5d3faa3 + 11bf984 commit 33fa7c0
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions streamerbot/2.guide/11.csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Explore all available C# methods at [API References > C# Methods](/api/csharp)


## Arguments
All C# actions have access to a Dictionary, `args`, containing the current argument stack.
All C# actions have access to a Dictionary<string, object>, `args`, containing the current argument stack.

::callout{icon=i-mdi-lightbulb color=amber}
In the event that the `args` Dictionary does not contain your key, a `KeyNotFound` exception will be thrown.
Expand All @@ -44,40 +44,34 @@ In the event that the `args` Dictionary does not contain your key, a `KeyNotFoun
::

::code-group
```cs [CPH TryGetArg]
string rawInput;
```cs [TryGetValue]
// If %rawInput% exists, store it in rawInput
if (!CPH.TryGetArg<string>("rawInput", out rawInput))
{
// Arg doesn't exist, stop execution
return false;
}
if (!args.TryGetValue("rawInput", out object rawInputObj))
return false; // Arg doesn't exist, stop execution
string rawInput = rawInputObj?.ToString();

// Do something with rawInput...
```
```cs [TryGetValue]
```cs [CPH TryGetArg]
string rawInput;
// If %rawInput% exists, store it in rawInput
if (!args.TryGetValue("rawInput", out var rawInputObj))
{
// Arg doesn't exist, stop execution
return false;
}
string rawInput = rawInputObj?.ToString();
if (!CPH.TryGetArg<string>("rawInput", out rawInput))
return false; // Arg doesn't exist, stop execution
// Do something with rawInput...
```
::

::callout{icon=i-mdi-lightbulb color=amber}
Special arguments `__source` and `eventType` must be accessed with their corresponding methods:
Special arguments `eventSource` and `__source` must be accessed with their corresponding methods:
::

::code-group
```cs [CPH GetSource]
EventSource source = CPH.GetSource();
EventSource source = CPH.GetSource(); // eventSource in args
```
```cs [CPH GetEventType]
EventType type = CPH.GetEventType();
EventType type = CPH.GetEventType(); // __source in args
```
::

Expand Down

0 comments on commit 33fa7c0

Please sign in to comment.