Skip to content

Commit f143bc8

Browse files
docs: update C# docs, add custom methods doc
1 parent ac2dbe5 commit f143bc8

File tree

12 files changed

+213
-224
lines changed

12 files changed

+213
-224
lines changed
74.3 KB
Loading
23.6 KB
Loading
Lines changed: 42 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,47 @@
11
---
22
title: Execute C# Code
33
description: Sub-action for writing advanced custom actions with C# code
4+
parameters:
5+
- name: Name
6+
type: Text
7+
description: |
8+
Optionally set a descriptive name for your C# sub-action.
9+
10+
::tip
11+
`Name` is required if you would like to share custom methods with the [Execute C# Method](/api/sub-actions/core/csharp/execute-csharp-method) sub-action.
12+
::
13+
- name: Description
14+
type: Text
15+
description: Optionally set a longer description detailing what your C# sub-action does.
16+
- name: Precompile on Application Start
17+
type: Toggle
18+
default: false
19+
description: By ticking this, your code will be automatically compiled when you start Streamer.bot so it is ready to go, instead of the first time the sub-action is executed.
20+
- name: Delayed Start
21+
type: Toggle
22+
default: false
23+
description: |
24+
When `Precompile on Application Start`{color=primary} is enabled, delay compilation until later in the startup routine.
25+
26+
::tip
27+
This is useful if you are **implementing UI** within your C# sub-action.
28+
::
29+
- name: Save Result to Variable
30+
type: Toggle
31+
default: false
32+
description: |
33+
Save the `bool`{lang=cs} result of the `Execute()`{lang=cs} method
34+
35+
::warning
36+
**This changes the default behavior of the sub-action**
37+
<br>
38+
By default, a method returning `false`{lang=cs} will simply stop execution of the entire action.
39+
<br>
40+
Enabling this option allows you to collect the result and also continue execution **regardless of the return value**.
41+
::
42+
- name: Variable Name
43+
type: Text
44+
description: When `Save Result to Variable`{color=primary} is enabled, define the name of the resulting variable.
445
---
546

6-
::callout{icon=i-mdi-bookmark color=green to=/guide/csharp}
7-
Learn more about custom code actions at [Guide > C# Code Actions](/api/csharp)
8-
::
9-
10-
::callout{icon=i-mdi-bookmark color=green to=/api/csharp}
11-
Explore all available C# methods at [API References > C# Methods](/api/csharp)
12-
::
13-
14-
## Views
15-
### Compiling Log
16-
Shows some general information based on what buttons you've pressed, this will show any compiler errors, and general information when trying to find references
17-
18-
### References
19-
List the references required for compiling your code.
20-
21-
::tip{color=amber}
22-
You can :shortcut{value=Right-Click} within the pane if you need to add specific references
23-
::
24-
25-
## Configuration
26-
Configuration options available under the `Settings` tab are outlined below:
27-
28-
::field-group
29-
::field{name=Name type=Text}
30-
Optionally set a descriptive name for your C# sub-action.
31-
32-
::tip{color=amber}
33-
`Name` is required if you would like to execute custom methods with the [Execute C# Method](/api/sub-actions/core/csharp/execute-csharp-method) sub-action.
34-
::
35-
::
36-
37-
::field{name=Description type=Text}
38-
Optionally set a longer description detailing what your C# sub-action does.
39-
::
40-
41-
::field{name="Keep Instance Active" type=Toggle}
42-
By ticking this option, your code will be kept alive for the lifetime of the Streamer.bot application.
43-
44-
This will allow you to **preserve data between calls** to this sub-action.
45-
46-
::tip
47-
As of Streamer.bot v0.2.3, this option has been removed and is enabled by default.
48-
::
49-
::
50-
51-
::field{name="Precompile on Application Start" type=Toggle}
52-
By ticking this, your code will be automatically compiled when you start Streamer.bot so it is ready to go, instead of the first time the sub-action is executed.
53-
::
54-
55-
::field{name="Delayed Start" type=Toggle}
56-
When `Precompile on Application Start` is enabled, delay compilation until later in the startup routine.
57-
58-
This is useful if you are **implementing UI** within your C# sub-action.
59-
::
60-
61-
::field{name="Save Result to Variable" type=Toggle}
62-
Save the `bool` result of the `Execute()` method
63-
64-
::tip{color=amber}
65-
Returning `false` without this option enabled will simply stop execution of the entire action. Enabling this option allows you to collect the result and also continue execution regardless of the return value.
66-
::
67-
::
68-
69-
::field{name="Variable Name" type=Text}
70-
When `Save Result to Variable` is enabled, enter the name for the resulting variable here.
71-
::
72-
::
73-
74-
## Actions
75-
76-
::field-group
77-
::field{name="Format Document" type=Button}
78-
Automatically format your code with proper indentation
79-
::
80-
81-
::field{name="Find Refs" type=Button}
82-
Attempt to automatically find some common references based on your `using` directives.
83-
::
84-
85-
::field{name="Compile" type=Button}
86-
Test the compilation of your code and check for errors.
87-
88-
::callout{icon=i-mdi-alert color=amber}
89-
This will also remove any references that are currently unused.
90-
If your code is stil in-progress, it could end up removing a reference that is actually needed.
91-
::
92-
::
93-
94-
::field{name="Save and Compile" type=Button}
95-
This will save your changes, and pre-compile the code so it's ready to go the first time the action is hit
96-
::
97-
98-
::field{name="Ok" type=Button}
99-
Save your changes
100-
::
101-
102-
::field{name="Cancel" type=Button}
103-
Discard your changes
104-
::
105-
::
47+
:read-more{to=/api/csharp/guide}
Lines changed: 43 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,48 @@
11
---
22
title: Execute C# Method
3-
description: Sub-action for directly calling a method defined in another C# code sub-action
3+
description: Execute a custom method defined in another Execute C# Code sub-action
4+
parameters:
5+
- name: Execute C# Code
6+
type: Select
7+
required: true
8+
description: |
9+
Select the [`Execute C# Code`](/api/sub-actions/core/csharp/execute-csharp-code) sub-action instance you would like to reference.
10+
11+
::warning
12+
You must configure the `Name` field in your `Execute C# Code` sub-action settings to display it here. [Read more >](/api/sub-actions/core/csharp/execute-csharp-code#configuration)
13+
::
14+
- name: Method
15+
type: Select
16+
required: true
17+
description: |
18+
Select the method to execute
19+
20+
::tip
21+
This can be any custom defined method, or even the main `Execute()`{lang=cs} method.
22+
::
23+
- name: Run on UI Thread
24+
type: Toggle
25+
default: false
26+
description: |
27+
Whether to run the method on the UI thread. This is useful if your method is spawning UI elements.
28+
- name: Save Result to Variable
29+
type: Toggle
30+
default: false
31+
description: |
32+
Whether to save the `bool`{lang=cs} result of the method to a variable
33+
34+
::warning
35+
**This changes the default behavior of the sub-action**
36+
<br>
37+
By default, a method returning `false`{lang=cs} will simply stop execution of the entire action.
38+
<br>
39+
Enabling this option allows you to collect the result and also continue execution **regardless of the return value**.
40+
::
41+
- name: Variable Name
42+
type: Text
43+
description: When `Save Result to Variable`{color=primary} is enabled, define the name of the resulting variable.
444
---
545

6-
::callout{icon=i-mdi-bookmark color=green to=/guide/csharp}
7-
Learn more about custom code actions at [Guide > C# Code Actions](/api/csharp)
8-
::
46+
Using this sub-action you can directly call into methods defined in any existing [Execute C# Code](/api/sub-actions/core/csharp/execute-csharp-code) sub-actions in your Streamer.bot instance.
947

10-
Using this sub-action you can directly call into methods defined in your existing [Execute C# Code](/api/sub-actions/core/csharp/execute-csharp-code) sub-actions.
11-
12-
Custom methods must be in the form of a return type of `bool` with no parameters:
13-
14-
```csharp [Example]
15-
public bool MethodName()
16-
{
17-
// your code here
18-
return true;
19-
}
20-
```
21-
22-
::tip{color=amber}
23-
If you have the selected `Execute C# Code` sub-action setup for `Keep Alive` and `Precompile on Startup` you can use `private` variables within the class to **preserve data between calls**.
24-
::
25-
26-
## Configuration
27-
28-
::field-group
29-
::field{name="Execute C# Code" type=Select}
30-
Select the `Execute C# Code` sub-action you would like to reference.
31-
32-
::tip{color=amber}
33-
You must configure the `Name` field in your `Execute C# Code` sub-actions to display here. [Read more](/api/sub-actions/core/csharp/execute-csharp-code#configuration)
34-
::
35-
::
36-
37-
::field{name=Method type=Select}
38-
Select the method to execute
39-
40-
::tip{color=amber}
41-
This can be any custom defined method, or even the main `Execute()` method.
42-
::
43-
::
44-
45-
::field{name="Run on UI Thread" type=Toggle}
46-
47-
::
48-
49-
::field{name="Save Result to Variable" type=Toggle}
50-
Save the `bool` result of the selected method
51-
52-
::tip{color=amber}
53-
Returning `false` without this option enabled will simply stop execution of the entire action. Enabling this option allows you to collect the result and also continue execution regardless of the return value.
54-
::
55-
::
56-
57-
::field{name="Variable Name" type=Text}
58-
When `Save Result to Variable` is enabled, enter the name for the resulting variable here.
59-
::
60-
::
48+
:read-more{to=/api/csharp/guide/custom-methods}

streamerbot/3.api/3.csharp/0.guide/0.intro.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ When your C# sub-action is executed, the `Execute()`{lang=cs} method is always c
4141

4242
This is where you should place your main code logic, as shown in the example below:
4343

44-
4544
```cs [Example.cs]
4645
public bool Execute()
4746
{
@@ -67,6 +66,7 @@ public bool Execute()
6766
```
6867

6968
### Custom Methods
69+
7070
You can also define your own custom methods within the `CPHInline`{lang=cs} class, and call them from within the `Execute()`{lang=cs} method.
7171

7272
```cs [Example.cs]
@@ -83,14 +83,30 @@ public void CustomMethod()
8383
}
8484
```
8585

86+
:read-more{to=/api/csharp/guide/custom-methods}
87+
88+
## Window Actions
89+
90+
Within the C# code dialog, you have access to several button actions:
91+
92+
| Action | Description |
93+
| -------------------- | ---------------------------------------------------------------------------------------------------------- |
94+
| **Format Document** | Automatically format your code with proper indentation |
95+
| **Find Refs** | Attempt to automatically find some common references based on your `using`{lang=cs} directives. |
96+
| **Compile** | Test the compilation of your code and check for errors. |
97+
| **Save and Compile** | Save your changes, and pre-compile the code so it's ready to go the first time the action is hit |
98+
| **Ok** | Save your changes |
99+
| **Cancel** | Discard your changes |
100+
86101
## Video Tutorials
102+
87103
Explore some introductory video tutorials on using C# in Streamer.bot
88104

89105
::card-group
90-
::card{icon=i-mdi-youtube title="C# Crash Course for Streamer.bot" to="https://youtu.be/rS5ZuIZV_y0" target=_blank rel=noopener}
91-
by nutty
92-
::
93-
::card{icon=i-mdi-youtube title="Streamer.bot C# Shorts" to="https://youtu.be/A7kizutsZnc?list=PLVmWn5RfnNsogzpk5loBoYXvWEZY-Qz6g" target=_blank rel=noopener}
94-
by TerrierDarts
95-
::
106+
::card{icon=i-mdi-youtube title="C# Crash Course for Streamer.bot" to="https://youtu.be/rS5ZuIZV_y0" target=\_blank rel=noopener}
107+
by nutty
108+
::
109+
::card{icon=i-mdi-youtube title="Streamer.bot C# Shorts" to="https://youtu.be/A7kizutsZnc?list=PLVmWn5RfnNsogzpk5loBoYXvWEZY-Qz6g" target=\_blank rel=noopener}
110+
by TerrierDarts
111+
::
96112
::

streamerbot/3.api/3.csharp/0.guide/1.variables.md

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,6 @@ In addition to `TryGetArg<T>()`{lang=cs}, you can also safely check if an argume
5050
```
5151
::
5252

53-
### EventSource and EventType
54-
Special arguments `eventSource` and `__source` must be accessed with their corresponding methods [GetSource and GetEventType](/api/csharp/core/events):
55-
56-
::field-group
57-
::field{name=eventSource type=EventSource}
58-
The event source that triggered the current action.
59-
60-
```cs [Example.cs]
61-
// Retrieve eventSource value from args
62-
EventSource source = CPH.GetSource();
63-
```
64-
::
65-
::field{name=__source type=EventType}
66-
The event type that triggered the current action.
67-
68-
```cs [Example.cs]
69-
// Retrieve __source value from args
70-
EventType type = CPH.GetEventType();
71-
```
72-
::
73-
::
74-
7553
## Global Variables
7654

7755
### Get/Set Global
@@ -167,4 +145,13 @@ public class TestClass
167145
List<TestClass> testList = new List<TestClass>(){...};
168146
string jsonSaveString = JsonConvert.SerializeObject(testList);
169147
CPH.SetGlobalVar("savingClass", jsonSaveString, true);
170-
```
148+
```
149+
150+
## Special Arguments
151+
152+
### Event Source & Event Type
153+
Special arguments `eventSource` and `__source` are enum values and must be accessed with their corresponding methods.
154+
155+
:read-more{to=/api/csharp/enums/event-source}
156+
157+
:read-more{to=/api/csharp/enums/event-type}

0 commit comments

Comments
 (0)